Fetching api response slow and not be stable

I need to get the value ( totaluser ) as soon as possible , but when the server change the data ( totaluser ) , the reponse is not stable about the time returning , sometimes get the reponse for 30ms and sometimes get for 5000ms , can someone give any solution to get this more stable and get better about the performance ? , i just want to get the value as soon as possible when the server update it? i am not coding the backend .

var refreshIntervalId =  setInterval(function () {
        fetch('**the link for api **')
            .then(res => res.json()).then((out) => {

            var variable = out.totalUser[0].count;

        if( variable > 20 ){
           // do something ...
        }
    })  
    }, 10);

Hi thank for your helping , i just want to get the totalUser as soon as possible when the server change the data so i fetched 10ms, but i am not coding the backend so i can use websocket ? Could you give me some code to refer about that ?