Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use a REST API, or Socket.io for a Geolocation App?

I need to track moving cars.

Should I post the location every time the location changes, and send it over the socket?

Or should make a REST API and post the location (from the tracked device) and check it (with the tracker device) every 10 seconds, regardless if the location changed or not?

(The App is being made with React Native)

like image 344
Emilios1995 Avatar asked Oct 18 '25 15:10

Emilios1995


1 Answers

Building HTTP requests by frequent updates requires more resources then sending messages through websocket. Keeping websocket connections open by a lot of users requires more resources than using HTTP. In my opinion the answer depends on the user count, the update frequency, whether you apply the REST constraints (no server side session) and which version of HTTP you use (HTTP2 is more efficient than HTTP1.1 as far as I know). I don't think this is something we can tell you without measurements.

The same is true if you want to push data from the server to the client. If you do it frequently and the update must be almost immediate, then websocket is probably a better choice than polling. If you do the rarely and the delay (polling frequency) can be a few minutes, then polling might be better.

Note that I am not an expert of load scaling, this is just a layman's logic.

like image 70
inf3rno Avatar answered Oct 21 '25 04:10

inf3rno