Session Based Auth System [state-full]
![Session Based Auth System [state-full]](/_next/image?url=https%3A%2F%2Fcloudmate-test.s3.us-east-1.amazonaws.com%2Fuploads%2Fcovers%2F662e9149ea7b8adaf16495b0%2Fe59a4233-21ac-418e-8af0-9057d2e04cdf.png&w=3840&q=75)
Session based auth is traditional method of auth and it is
state-fullmeans we storesessionsof user in memory or DB and sharesession_idto user to verity his identityThis method is gold standard for
monolithapplication where front-end and back-end are served from same domain.
How it’s work
Login - user submit their credential to server
Verification and creation - if credential is correct against DB, it create a
sessionin DB and generate a uniquesession_idCookie - Server send back response with header of
set_cookieincludessesson_idBrowser - it automatically store the
cookieSubsequent request - in every future server request, browser attach cookie of
session_idin header requests.Server validation - it pull the
session_idfrom header cookie and look up in session storage if it matches thenprocessthe request.
Methods in session based auth
I said it earlier it is not idle for multi-server system, but there is practical methods to achieve this using following methods.
1. Replication of Session storage
Why we use this method ?
Incase of multi server user 1st login req. go to
auth_serverthat create and save session insession_storage_DB-1Because of
load-balancerthe next req. withsession_idheader is route toserver-2but it failed to validation because their session is not stored insession_storage_DB-2it leads logout of user.To resolve this issue we use replication session storage
How it’s works ?
When any one server creates or updates a session, it immediately broadcasts that change to the data-grid, which then updates all other servers.
Drawback
Memory overhead - each server contain all the session which consumes your all available RAM
Complexity - To keep server session up to date in Realtime is difficult
2. Centralized Session storage
why we use this method
It resolves memory overhead issue
To make system less complex
How it’s work?
Here we use common session_storage_DB for both servers can fetch and validate the session_id against single session_storage_DB
Drawback
Single Point of Failure: If the Session_storage_DB goes down, no one can log in



![Token Based Auth System [state-less]](/_next/image?url=https%3A%2F%2Fcloudmate-test.s3.us-east-1.amazonaws.com%2Fuploads%2Fcovers%2F662e9149ea7b8adaf16495b0%2Ff4e28b41-8d8d-42bd-8b0c-e3b86fbebda5.png&w=3840&q=75)