Emilios1995
Emilios1995

Reputation: 507

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)

Upvotes: 4

Views: 2169

Answers (2)

gzost
gzost

Reputation: 2445

I would use WebSockets. For small deployments and low-frequency updates basically anything works, but with WebSockets you have technology that scales better in the long term. (And no, I would not consider this premature optimization, since the choice of technology here does not mean unnecessary initial overhead.)

Shameless plug: If you're using WebSocket, you could take a look at Crossbar.io - http://crossbar.io, or WAMP (http://wamp-proto.org) in general, which provides messaging mechanisms on top of WebSocket and should work well for you use case. I work for the company which is at the core of this, but it's open source software.

Upvotes: 3

inf3rno
inf3rno

Reputation: 26137

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.

Upvotes: 3

Related Questions