Managing incoming server events from multiple pods

Currently, I am developing a NodeJS server that has an /events endpoint for sending events to clients using SSE. In addition to this endpoint, there are multiple routes for handling POST requests.

I am faced with the challenge of setting up this system so that it can support multiple pods. At the moment, I have a load balancer in place to maintain the connection between users and pods until the client disconnects. However, post requests from clients may be directed to different pods.

My goal is to ensure that each pod can send a message containing the user ID and that the correct pod, which has an open connection with the user, receives this event and sends it to the client.

Although I have considered using Redis for this purpose, I am exploring if there are any native solutions within NodeJS or Kubernetes that eliminate the need for it.

Answer №1

To achieve this, you have the option to utilize Services or go through the load balancer.

When using a service, session affinity can be implemented in the following manner:

kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  sessionAffinity: ClientIP

If you prefer sticky sessions with the load balancer:

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

Express (generator) is failing to load custom scripts located in the public folder

I'm new to node and express and I'm facing a problem. I want to load a custom script.js from the public folder, but it's not loading. There are no errors in the console or anything in the network tab. When I try to access the URL localhost:3 ...

Is it necessary for my Parse Server app to be constantly running on my server?

Setting up a parse server on my own server is proving to be quite the challenge for me. As a newbie, I've managed to install everything I need (Node v7.8, NPM v4.4.4) on my Ubuntu 16.04 LTS machine. Following the example app for the parse server seeme ...

Managing multiple versions of a document in a blog storage system with MongoDB and Node.js

In the process of developing a blog site, I want to incorporate a feature that keeps track of the changes made in previous and current versions of a blog post. One method is to create a separate history collection, but how should I manage the document? S ...

Is it feasible to implement Single Sign-On for a NodeJs application using NTLM-LDAP integration?

I am faced with the challenge of setting up Single Sign On for my Node application within an Active Directory Domain Network. Both the application and the clients trying to access it are on the same network, which should simplify the process. While I hav ...

Building nested schemas in Mongoose for handling multiple arrays of objects

I'm currently in the process of developing a REST API using node, express, and MongoDB for a web application that has three main sections on the frontend: Quotes Stories News When a user clicks on Quotes, they should only see quotes; the same goes ...

Activity Timeout in Azure Durable Functions

Within my activity function, I have the following code block: do { await timeout(500); } while (await getStatus() === false); Here's what each part of the code does: function timeout(ms) { return new Promise(resolve => setTimeout(reso ...

Setting up reverse proxy rules for GitLab on a Node.js Express server can be achieved using the following

I am currently in the process of developing a Node.js application to serve a private GitLab server. Initially, I had it set up with Apache, but now I am looking to switch over to using my Node.js application instead. Most of the functionality is there. Th ...

The system does not acknowledge 'grunt'

I am a beginner when it comes to working with grunt and currently using: Node: 6.9.2 npm: 3.10.9 Operating System: Windows 7 Every time I attempt to install grunt by running the command below: npm install -g grunt-cli An error message pops up saying: ...

How can Next JS automatically route users based on their IP address?

Currently, I am using express and the following method within app.get('/anyPath') to identify the IP address of the client: var ip = req.headers['x-real-ip'] || req.connection.remoteAddress if (ip.substr(0, 7) == "::ffff:") { ...

What's Next? Redirecting Pages in Node.js Express after Handling POST Requests

Is it possible to redirect to a different page from a post request? module.exports = function(app) { app.post('/createStation', function(request, response){ response.redirect('/'); //I'm having trouble getting ...

What is the process for generating a file in Node and Express on my server and subsequently transmitting it to my client for download? My technology stack includes NextJS for both frontend and backend operations

How can I generate a file using Express and Node on my server, and then successfully download it to the client? My tech stack includes NextJS for both frontend and backend, and with React as the frontend framework. I'm facing difficulty figuring out h ...

Issue encountered during react-router-dom installation

Warning: npm has disabled recommended protections by using --force. Please run the following command to install react-router-dom in your project file: npm install react-router-dom Error code ERESOLVE encountered while resolving dependencies. Error! ERES ...

Discord.js Tutorial: Triggering a Message Upon Channel Deletion

Curious to know if a bot can send a direct message to a user when a channel is deleted. ...

Node.js request body is not returning any data

UPDATE: @LawrenceCherone was able to solve the issue, it's (req, res, next) not (err, res, req) I'm in the process of building a MERN app (Mongo, Express, React, Node). I have some routes that are functioning well and fetching data from MongoDB. ...

Setting up NestJs with TypeORM by utilizing environment files

In my setup, I have two different .env files named dev.env and staging.env. My database ORM is typeorm. I am seeking guidance on how to configure typeorm to read the appropriate config file whenever I launch the application. Currently, I am encountering ...

Array of Objects Returned by Mongoose

Need help understanding an issue. I'm facing a problem where my API is returning the whole object as an array for one route, even though the schema is identical to another route that returns the object correctly. The only difference I can see is tha ...

Learn how to bootstrap Angular JS with this step-by-step tutorial 2

I am currently following a tutorial on Angular JS on my Windows platform. I am stuck at the bootstrapping page where the app is supposed to run. I have already installed Node JS and downloaded GitBash. However, when I open the command prompt and type &apos ...

communicating an item between app.js and routes in node.js

Here is the content of my app.js: var express = require('express'); ... var model = require('./models/my_model'); var routes = require('./routes/index'); var app = express(); app.use('/', routes); var middlewar ...

Utilizing i18n and ejs for client-side rendering

I am in the process of developing a music platform utilizing NodeJs, Express 4.0, and EJS as my template engine. To ensure continuous playback of music while navigating through the site, similar to SoundCloud, I load my site content dynamically through AJA ...

Optimizing express server dependencies for a smooth production environment

After developing an application with a React front end and a Node server on the backend, I found myself wondering how to ensure that all dependencies for the server are properly installed when deploying it on a container or a virtual machine. Running npm ...