I understand that token based authentication is widely used for microservices, esp, when there is horizontal scaling.
For microservices also, can we use sessions by storing it in database? The series of requests would be :
- First request, HTTPsession is created and session id stored in a database table along with unique username.
- Second request is sent with this session id, and any microservice instance can serve this request. Server has to verify this session and user with that of the database record. If sesssionid+username combo is present in database and sessionid is a valid one, then serve the request else redirect to login page.
- When logout is clicked, session is invalidated and db record is also removed.
Will this not be a good session management for microservices? Do Microservices always have to be stateless?