What is the best choice for a Geolocation App: REST API or Socket.io?

Currently, I am working on a project that involves tracking moving cars.

I am contemplating whether to update the location every time it changes and send it over through the socket.

Alternatively, would it be more efficient to create a REST API where the tracked device posts its location at regular intervals (e.g. every 10 seconds), allowing the tracker device to check it even if the location remains the same?

(Just to clarify, this application is being developed using React Native).

Answer №1

When it comes to building HTTP requests with frequent updates versus using websockets for messaging, the key factor to consider is the resource usage. Maintaining open websocket connections for many users can be more resource-intensive than utilizing HTTP, depending on various factors such as user count, update frequency, adherence to REST constraints, and the version of HTTP being used (HTTP2 being more efficient than HTTP1.1). Ultimately, the best approach may vary and should ideally be determined through measurements.

A similar consideration applies when pushing data from server to client. If real-time updates are crucial and frequent, websockets might be preferable over traditional polling. On the other hand, if updates are infrequent and a delay of few minutes is acceptable, then polling could be the better option.

It's important to note that these insights come from a non-expert perspective on load scaling considerations.

Answer №2

My preferred method would be utilizing WebSockets. While other technologies may suffice for small deployments and infrequent updates, WebSockets offer scalability in the long run. This decision is not premature optimization as it does not entail unnecessary initial overhead.

As a shameless plug, consider looking into Crossbar.io - , or WAMP () which enhances messaging capabilities on top of WebSocket and suits various use cases. Although I am affiliated with the core company behind this software, it is open source.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to execute a script on the Firebase backend?

I am currently working on a Firebase web project that involves Google cloud functions and a database. I now need to find a way to run a script on the backend in order to transfer data within the databases. Can anyone guide me on how to execute this scrip ...

Issue: The code mentioned below is functioning perfectly during development, but once it is deployed on Heroku, it exhibits sporadic behavior

Struggling to make socket.io function properly on Heroku, encountering issues with code inconsistency between development and deployment. The problem persists even after uploading to Heroku: 1. No unusual activity in the logs. 2. Data saved to the databa ...

The SQL instance on Google Cloud Platform is currently unable to establish connections with a **nodejs application** when using custom user credentials

After adding my IP to the whitelist, I successfully connected to a Google Cloud Platform SQL Server instance using the sqlcmd utility in my terminal. sqlcmd -S <ip-address> -U <username> -P<password> However, when attempting the same co ...

Heroku App Breaks Down - Fails to Render Static HTML Content (Express Server)

Despite my best efforts, I keep encountering this persistent error on Heroku whenever I attempt to serve a static HTML page with some basic JS, images, and CSS. I diligently followed all the advice from SO, made adjustments to index.js, restructured files, ...

At what point does the event loop in node.js stop running?

Could you please enlighten me on the circumstances in which the event loop of node.js terminates? How does node.js determine that no more events will be triggered? For instance, how does it handle situations involving an HTTP client or a file reading app ...

Struggling to locate the node module 'node:fs' while working with JavaScript and attempting to deploy to my personal Linux server

Error: Module 'node:fs' Not Found at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:692:17) a ...

The rxjs package is failing to meet the peerDependencies requirements of its sister packages

After running npm install, I came across this error: npm ERR! Windows_NT 6.1.7601 npm ERR! argv "c:\\Program Files\\nodejs\\node.exe" "c:\\Program Files\\nodejs\\node_modules\\npm\ ...

HTTP / HTTPS GET Request Alexa Skill - "The result is not valid" Lambda Reply

Currently, I am in the process of developing an Alexa skill that assists users in finding the nearest Kaiser Permanente hospital, clinic, or pharmacy. During testing, if one of the three specific keywords is used, I encounter an error message: The response ...

The request body is not showing up as a key-value pair, while the request headers and other parameters are visible

Example of 'Advanced REST Client' Request I am currently using Postman and Advanced REST client to create a simple POST request based on the code below: 'use strict'; var express = require('express'); var bodyParser = requir ...

What is the reason behind appengine-rest-server returning JSON strings instead of integers for properties?

I set up a basic REST server on GAE utilizing the appengine-rest-server. The structure of my database is as follows: SomeString = db.StringProperty() SomeInt = db.IntegerProperty(default=0) SomeFloat = db.FloatProperty(default=-1.0) SomeDateTime = db.Dat ...

Using promises in Node.js code allows for more efficient and organized

I am a beginner with the Q library and looking to improve my code by utilizing promises. The following code is currently synchronous: var items = getItems(); var relatedItems = processItems(items) saveRelatedItems(relatedItems) markItemsAsProcessed(items ...

Encountered a 'Failed to install package' error when attempting to create a new project using ng command

There are errors that I encountered while trying to execute the command: ng new project I need help identifying what went wrong. npm WARN tarball tarball data for @angular/compiler@~7.1.0 (sha512-ua6Wh+c5XzxAeJT6guwAFYnwa1XzJpncppUrceRXIS9VAn9X7ApxRr45Dvb ...

Ensure the backslashes are removed from the AWS Lambda string API response

I have an AWS Lambda function where I am sending a string as my final response let abc= `"phone_exist":"0","calls":"0","lastaction":"0"` callback(null,abc); Output: "\"phone_exist\":\"0\",\"calls\":\"0\",\"l ...

Streaming a multipart file upload directly to an S3 bucket

Seeking to transfer a file upload received from a multipart request to an S3 bucket utilizing express and aws-sdk. The upload function is utilized, which can utilize a readable stream for the Body parameter. await s3Client .upload({ Bucket: 's ...

Avoid opening the "Manage npm modules" option by right-clicking

I've been diving into Shawn Wildermuth's course on Node.js for .NET Developers and have successfully installed NodeJS Tools for Visual Studio from nodejstools.codeplex.com. After getting everything set up, I created a "NodeJS Blank Website." How ...

Error in polling when integrating Coinpayments with Node.js

Everything is running smoothly with the code, but after a few seconds, an unexpected 'Polling error' message pops up in the console. I tried looking for solutions online, but unfortunately, I couldn't find anything helpful. If anyone has a ...

Tips for incorporating routes in Polka.js in a way that resembles the functionality of express.Route()

One of the challenges I am facing is trying to import route logic from another file in my project. While using Express.js, this could be done easily with express.Route(). However, when attempting polka.Route(), an error occurs stating that Route doesn&apos ...

Perpetuate the Node.js experience with the perpetual execution of shell

I have a requirement to manage my long-running scripts through a web interface. if ($_GET['list']) { $list = shell_exec("forever list"); echo ($list); } However, when I try to execute the above code, it returns the output: 'No f ...

Accessing files from various directories within my project

I'm working on a project with 2 sources and I need to import a file from MyProject into nest-project-payment. Can you please guide me on how to do this? Here is the current file structure of my project: https://i.stack.imgur.com/KGKnp.png I attempt ...

Is there a way to send URL variables to express.js similar to how it's done in PHP?

Currently in the process of converting my PHP website to Express.js. There are numerous scripts on my frontend that generate links in the format page.php?id=10&something=anything. Is there a way in Express.js to capture variables from URLs structured ...