Search code examples
design-patternscloudmonitoringmicroservicesinstrumentation

How to account for open sessions in a stateless service


I am converting my app from a classic service to a microservice. I need to count total number of open sessions.

My classic version was writing a local windows perf counter: +1 on session open, -1 on session close. If the service died unexpectedly, the new instance reset the counter during start. A remote monitoring service was collecting the counter from all instances and showing total and average.

My new service writes counters using diagnostics library that pushes the values to a remote monitoring service.

I do not understand how to reset the counter if the service dies unexpectedly. The only idea I got is to start collecting heartbeats from each service and reset the counter if the service dies, but it seems to be over-design.

Are there more elegant patterns to do a reliable accounting for open sessions for a stateless service?

Is there a standard terminology for this scenario in microservice management systems?


Solution

  • Well, if your services are stateless and you would like to take silent crashes into account, why not to query that information from the services, which are currently active, when you need? Each service knows how many active sessions it has. If a service doesn't answer the request, it's dead.