<p>I am working on a NodeJS based server that exposes <code>/events</code> endpoint, to send events to client via sse. Alongside this endpoint I have multiple routes for POST request handling.</p>
<p>I am trying to figure out how to set all of this up in a way that works for multiple pods. Right now I have load balancer setup to keep connection between user and pod alive until client disconnects, however when client makes post requests these can be routed to different pods.</p>
<p>I need to ensure that each pod can emit a message with user id and that this event is caught by correct pod that has open connection with the user and sent to the client.</p>
<p>I have considered redis for this, but am wondering if NodeJS or Kubernetes exposes something that doesn't require it.</p>

Ilja
<p>You should be able to do it with Services or through the loadbalancer.</p>
<p>With service you can use session affinity :</p>
<pre><code>kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  sessionAffinity: ClientIP
</code></pre>
<p>with the loadbalancer sticky sessions :</p>
<p><a href="https://kubernetes.github.io/ingress-nginx/examples/affinity/cookie/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/affinity/cookie/</a></p>
