2:44 4:41 introduction to the problem of stateful application 5:50 problem: impossible to scale up 6:10 6:51 stateful with load balancer 8:36 stateless example 8:52 Alice is using REST, State transfer 11:14 server sends Alice a *token* 11:34 then Alice will send request always with the token
I work full time as a software developer, I stumbled across this while doing some research, and what can I say? you have an amazing character. Well explained :)
Shubham Batham sending a signed and time-stamped response token of love to all my subscribers in india ❤️ passcode to decrypt “stay awesome” thanks for your comment!!
Hey Nasser, your video is simply superb. Hatsoff. As your voice is BOLD and STRONG, one thing i visualised you as you will look like "Vin Diesel". By seeing your DP, then i realise you. Take a Bow.God bless you....:-)
I am hooked to your videos and as a junior back end developer i am learning a lot seeing things from different perspectives in my job. Thankyou so much
God bless you sir, when no one could explain me this thing...u did it in such a simple way. And yeah that accent of ur's its awesome....I can listen to your lectures for hours
nice video! i really appreciate videos like this that talk about real concepts/use cases in a simple way that you can watch on down time. keep at it cause it looks like the videos you're making are really cool!
Brilliant explanation champ! I've watch about 3 or other videos (each being 2 or 3 times longer) and NOT ONE of them came close to explaining it this comprehensively! Well don and a sub from me!
TL;DR: Stateful is basically keeping track of the state a user might find itself in (good example would be whether it is logged in or not). Stateless is using an alternative solution (for example using a token response solution) instead of keeping track of the state of the user to keep things scalable (especially useful for example when running a load balancer set-up). The latter often goes in hand with a lot of caching on the back-end side of the app.
Well explained. Just watched another video on stateless v stateful and this was my exact question: Wouldnt the ideal be tokenization with API? It seems like a cache has the same issue unless the cache itself is just another word for intermediate database. Thank you for clarifying that this is exactly the case and how this can be accomplished scalably.
Awesome video, I understand most of the good points of stateless, I guess making a web application whether a session is an important concern but not important at scaling we probably would use php session as a way to maintain the session or any other programming that gives us this set of tools. but regarding the we wouldn't scale horizontal, thanks man
great video as useful but i know that LB use algorithm like Consistent hashing to ensure that the same user will enter the same server to get benefit of stored data in the cash rather than resend all the info again > iam right ?
That is Correct if your app is stateful that it requires al requests from client to go to it then yes LB can use sticky session algo or iphash to make sure all requests go the server
Natalie Schulz Glad you find was useful, checkout the rest of the content in the channel where we explain other software engineering topics by example. Cheers :)
Check out my udemy Introduction to Database Engineering course database.husseinnasser.com Learn the fundamentals of database systems to understand and build performant backend apps
Correct me if i am wrong; if use jwt for session authentication(secrets on server itself) i wouldn't have to make so many calls to db(as when using session keys), making it nearly as efficient as stateful?
Saurabh Agrawal that is correct. JWT is better than session keys, JWTs has signature in them allowing server to quickly verify it Without hitting the db. They are also still stateless because the client sends the jwt with each request. So you can restart the server and the client can hit completely a different server and still be served . With session keys (what we explained in this video we have to verify the key by hitting the db) Good question
Good. I think the same way a token is stored in the DB and queried by all instances of system, a sessionID (localStorage of any kind of native app local storage) can be used with the same results in computing cost. The main PROs of using stateless is regarding to JWT, a way to validate tokens by the information it contains itself and not by querying the DB. Sessions ID and Tokens can be managed the same in backend and frontend, but for exposure to any client/platform, JWT is the way to go right now also because its granularity about granting specific permissions. Thank you.
good info. but it is actually possible to scale horizontally with stateful applications. I have done this in the past using a load balancer and sticky sessions. You can use sticky sessions to redirect the user requests to the same server that already has the session for the user.
Correct, you can scale stateful apps for sure with clever logic. However if that server to which the sticky session is locked on is restarted the application breaks.
What if we use Sticky connections in the load balancer ? Could it work properly if we scale Stateful applications horizontally ? Putting aside eventually crashes on servers that may not occur frequently.
Augusto Napuri that would work and would scale nicely. As you said if the server crash the client will have to login again since they will hit a new server. Another disadvantage is if the server is overloaded and latency dropped as a result its difficult to move client to another server in a smooth manner.
luls good question! The client is transferring the state (token) all the time with each request and the server does not hold the state it merely connects to the database to check if the token is ok. So if you truly think about it our entire system is still stateful by the way because we are storing the token (state) in the database but our application (hosted on server1/2) is stateless. The client is of course stateful because it holds the token. Any layer that holds a state in its memory or disk is called stateful. While our backend app doesnt hold anything so if you restart it we can still work just fine because the client will always send the state to us. Thus the state transfer in REST. Hope that helps :)
Sir, I am just about to start my second year at university, with an assignment to develop a web application and, after watching your videos, I believe I have a higher status than God. XD Jokes aside, honestly, thank you so much!!!
Zacharias King thanks Zach for the love and comment! Best of luck in your assignment!! Take a look at the other content of the channel, more cool stuff for you! Cheers
But in a stateful app, the server still has to use cookies to authenticate or recognize the user, and when you meant we have to hit the db every time to query for the token, it sounds pretty bad, but isn't that information also cached somewhere to tie in with the cookie expiry, because if were to really look at it sometime a single page might send around 20 to 30 requests to get different information from a stateless backend(REST) but it cannot afford to authenticate the user 20 times right ?
It looks like the only difference is: Stateful: save the session info in service. Stateless: save the session info in 3rd party component, say database
Glad you enjoyed it! I made another video about how Amazon Alexa is stateless maybe you will enjoy that as well ua-cam.com/video/zhwMv5RxGew/v-deo.html
For the stateful example, if the client uses a cookie and the server stores a session token in DB, I think we can solve the problem of horizontal expansion?
Thanks Yuan, yeah if you kept the session in the server memory and also stored it in DB you will be able to scale. I am assuming you will validate the session again the server memory first? (Some sort of cached data structure that tells you who is the user ) If the session id doesn’t exist in the server you can hit the DB and cache, if it does than all good. sure works, the only limitations now is that if the session is now invalided (manually removed from the database) you need to also write some logic to invalidate the session from each server that cached the session. There are ways to solve that but you just need to be aware.. another stateless approach is to use JWT (check out my video on JWT if you are interested to learn more on the topic)
Authentication is an excellent example of just how silly webdev can get. In a statefull application you logon to server 1, that server checks your credentials, records your loggerd-in status and you get a cookie that refers to that state. This is considered bad because server-2 needs to share some storage with server-1 to know if the cookie is valid and who it belongs to. In "stateless" application you logon to server-1, that server checks your credentials and gives you a cookie that that server-2 can also verify as being authentic (like a JWT). The problem is that the state that is received by server-2 *MUST* be verified against the same database that server-1 used to create it, for the simple reason that the user may have been denied access since the token was created. You *MUST* verify. So, statelessness does not really change anything from a serverload perspective,it just sneds bigger tokens because you need to use something like JWT. The hardware on the server side is identical, withidenticalproblems that, let's face it, are not really problems at all. Replicating data among databases is not an issueunless you are a gigantic websitewith hundreds of servers but by then you will have heard of sharding.
What about storing the session in redis, and all the server instances reaching looking for the session. I mean redis is a cache as well but it can persists
Cool video. But got me thinking a bit. I am not sure I am completely with you in here. Please correct me if this is wrong: the difference in your examples is only the fact that in the 1st example you cache the value in server1 while on the 2nd example you don't cache the values, you always check the token against the db. Isn't a more 'stateless' example a scenario where you can rely on the information on the token to do the validation (jwt)?
João Salgado that is correct, when I mention stateless and stateful in the video I was referring to the application that is hosted on the servers. So in the first case my application is stateful (cant scale) and in the second case my application is stateless. However the entire system still has a state which as you mentioned its in a database. Building a real stateless “system” is very hard because most of the time you probably need to store your state somewhere. Thanks for your comment!
What about using JWT to avoid DB calls at every request for validating the token? This keeps the stateless architecture intact by also covering its downsides. Doesn't it?
i think i got it, in a nutshel, stateful means that the server store information about that "session", but in the stateless the token doesnt have to be saved also? gonna read more about it, great video btw!
Thiago Dias That make sense, you can watch the new video about the same topic with examples. ua-cam.com/video/nhwZn6v5vT0/v-deo.html thanks for your comment
why store the token in the database? isn't the point so that you can decrypt it using some secret stored in an environment variable so that you can verify that the token came from you (and not tampered with) and thus you don't have to query the database to give access to protected resources?
Somebody please help me understand this concept. If we have a stateful application and are using load balancing with consistent hashing then that would solve the problem of failed viewProfile request or not?
You are one of the best I've ever followed but I think you've missed something in this video. The matter is not about where to store the data (in memory or in DB or in a file or whatever the place is) !! It's all about, DO YOU STORE IT OR NOT for next requests handling purposes? If the server can process a request without relying on an earlier request then it's STATELESS. If the server needs information from previous requests to be stored (in memory or DB) in order to process the current request then it's STATEFUL. REST would help to understand that since it's stateless. It sends the STATE of RESOURCE (which could be a USER) within the request every time without saying: "Why I should send it every time. why not just set it in a DB and things will be fine and stateless! 😅" I think, as a monolith application, no way to not be stateful but as a microservice, you could have one service that is stateful (for authentication and authorization) and other services are just stateless (pure business logic and the state of that logic will be sent through REST or whatever). What do you think? Do I have a point of view?
Hi, I still don't understand the stateless application. At first, the user sends a request to Load Balancer. This request may be passed into server 1. Server 1 sends back a token to the client. However, how can the server 2 still understand the request from the client? The server 2 doesn't know the token that belongs to a certain client?. Correct me If I am wrong. Could you explain this process again. Thank you
Because Server 2 will query the database to understand if the token is valid. so the application doesn't store the state in itself but is stored somewhere else (the database) that is why we say the application is stateless but the system remain stateful.
@@hnasr Thank you so much for your great explanation. Now I fully understand the stateful and stateless system. In summary, the stateful means the Server stores the information of the user by itself. Stateless means the server doesn't store the information of the user, but I still can understand the request is valid or not based on the token (which is saved somewhere).
Hello Sir, I am fan of your video. I have one question if I have to use the stateful service there is multiple servers how do we sync the information across different machines?
What's the difference between a token and a cookie? Why is a cookie considered stateful and a token stateless? Is there no record of the token server side? By what process is it authenticated then?
Explanation is good. Thank you .. Would you mind clarifying my doubt ? is this concept used only for a Web applications ? or any Services ? Sorry if its a dumb question.. As I am new to the dev, curious to know. :)
Jyotsna Doddi good question! No it applies to any kind of service that is consumed by many clients. Whether this is on HTTP or raw TCP or any other protocol. As long as the service is consumed via a client, each request should be treated independently from previous requests.. hope that helps :)
If you were my professor, I would be ready to sit in your lecture for hours. Beautiful explanation
Nikhil Balwani im humbled ❤️ thanks
If he were my professor, I would be sitting at FAANG now.
And you would land any job you want, he exolains concerts with simplicity and efficiency
Even 3 years later this explanation is one of the best on the web. Thanks a bunch mate!
It is worthy of investing 14 minutes of your life. Thanks Hussein
2:44
4:41 introduction to the problem of stateful application
5:50 problem: impossible to scale up
6:10
6:51 stateful with load balancer
8:36 stateless example
8:52 Alice is using REST, State transfer
11:14 server sends Alice a *token*
11:34 then Alice will send request always with the token
wow, indented sub-chapters. UA-cam should support MD for comments. 🔥🔥
Been programming over a year and never realized the correlation between REST and Stateless. Mind = blown. THANK YOU.
Stateful Example: 1:10
Stateless Example: 8:30
Stateless vs Stateful pros and cons: 13:30
ونعم ابوعلي
JWT changed the world!
I work full time as a software developer, I stumbled across this while doing some research, and what can I say? you have an amazing character. Well explained :)
Matthew Spiteri Thank you so much for your wonderful comment. Glad to see fellow software developers here. Best of luck !
Man am I glad I found someone that really knows how to really explain something. Great video ! 👍🙋♀️
Thank you Claire 🙏 I am glad you enjoyed the content and found it helpful
This video makes a lot of other web app concepts so much more clearer. Thanks a mil!
with stateless you can read the token with your secret token in server to get basic info no need to search in db or any temporary db in each requests
stateful : 세션변수 이용/ 서버에 저장
stateless: 토큰 사용
Sending a long ass token of appreciation all the way from India !! Great & Interesting explanation.Thank you !!
Shubham Batham sending a signed and time-stamped response token of love to all my subscribers in india ❤️ passcode to decrypt “stay awesome” thanks for your comment!!
This is the best tutorial I have ever seen in my life. I'm awed!.
Your explanation is far more better than my college lecturer
Hey Nasser, your video is simply superb. Hatsoff. As your voice is BOLD and STRONG, one thing i visualised you as you will look like "Vin Diesel". By seeing your DP, then i realise you. Take a Bow.God bless you....:-)
Raghu Vardhan Saripalli Raghu 😍😍 thanks my friend
I am hooked to your videos and as a junior back end developer i am learning a lot seeing things from different perspectives in my job. Thankyou so much
I'm on a marathon of your videos man. Awesome content
Enjoy 😊
God bless you sir, when no one could explain me this thing...u did it in such a simple way. And yeah that accent of ur's its awesome....I can listen to your lectures for hours
nice video! i really appreciate videos like this that talk about real concepts/use cases in a simple way that you can watch on down time. keep at it cause it looks like the videos you're making are really cool!
mollycrime Thanks! I try to give examples where I can from my personal experience working with a technology. Appreciate it!
I can listen to on any topic you teach, I love your teaching style and voice. I am so glad I came across this channel.
This is the best explaination on youtube
I am from Electrical background still understand it, nice explanation with diagram.
Great video Hussein. Thanks for the example.
Just logged in to comment a word of appreciation. Glad I found this channel. Beautiful content
Appreciate it ❤️❤️
Thank you very much for your videos , I dare anyone to watch you explaining a concept whatever the complexity of the concept and not understand it ❤❤❤
Sir, you really explained well. I am a 9th-grade student and I was completely able to understand what you meant.
Brilliant explanation champ! I've watch about 3 or other videos (each being 2 or 3 times longer) and NOT ONE of them came close to explaining it this comprehensively! Well don and a sub from me!
your channel is a gem!
TL;DR: Stateful is basically keeping track of the state a user might find itself in (good example would be whether it is logged in or not). Stateless is using an alternative solution (for example using a token response solution) instead of keeping track of the state of the user to keep things scalable (especially useful for example when running a load balancer set-up). The latter often goes in hand with a lot of caching on the back-end side of the app.
Great explanatio I think nowadays JWT solved the problem of querying db each time we make request.🤔
dude just thanks, really helped to quickly get a grasp of it
It's no longer over my head. Thanks
15 minutes ago I couldn't properly articulate the difference between stateful and stateless. Now? I might upload a course on Udemy. :))
Plain and simple. Thanks Hussein
Nice explanation, but I'd add that stateless apps can be less costing if some caching is implemented between the DB and app servers.
Correct! Just make sure to add logic to invalidate the cache
Very well explained. Good Job Bro. It clears my concept for stateful and stateless 🌹
Wow ! Simply an amazing explanation, now only I understand what it means 'State Transfer' in ReST, thanks, keep explaining.
just learned about load balancers too bless you ser!!!!!!!!
Very good explanation, i want you to teach a whole class of everything i want to learn!!!!
You explained nicely.. Thanks a lot.
This was amazing man!! Loved the way you impart things to the viewers!! High Five!
Best explain ever..Many thanks
🙏
Well explained. Just watched another video on stateless v stateful and this was my exact question: Wouldnt the ideal be tokenization with API? It seems like a cache has the same issue unless the cache itself is just another word for intermediate database. Thank you for clarifying that this is exactly the case and how this can be accomplished scalably.
Your explanation made me feel really "cool" and "lit" because I was able to understand this 😂 Definitely giving this video a like! 👍
Jordan Theisen Jordan you are cool and definitely lit 🔥 thanks for your comment!
Awesome video, I understand most of the good points of stateless, I guess making a web application whether a session is an important concern but not important at scaling we probably would use php session as a way to maintain the session or any other programming that gives us this set of tools. but regarding the we wouldn't scale horizontal, thanks man
Kevin Montalvo Flores exactly well said. It is a trade off that you as a software engineer/architect make.
Thanks a lot! It was crystal and clear explanation. Easy to understand. Subscribing you!
Thanks for the sub! appreciate you dear enjoy the content
great video as useful but i know that LB use algorithm like Consistent hashing to ensure that the same user will enter the same server to get benefit of stored data in the cash rather than resend all the info again > iam right ?
That is Correct if your app is stateful that it requires al requests from client to go to it then yes LB can use sticky session algo or iphash to make sure all requests go the server
Very well explained! keep the videos coming!
Thank you for simple explanation
very clear and easy to understand by the excellent explanation. Thank you so much.
Wonderful explanation
This is outrageously good. Thank you, mate!
Awesome Video ! Glad I found this - I am VERY NEW to Web Dev and this broke this complex subject down easily :) THANKS
Natalie Schulz Glad you find was useful, checkout the rest of the content in the channel where we explain other software engineering topics by example. Cheers :)
Check out my udemy Introduction to Database Engineering course
database.husseinnasser.com
Learn the fundamentals of database systems to understand and build performant backend apps
Correct me if i am wrong; if use jwt for session authentication(secrets on server itself) i wouldn't have to make so many calls to db(as when using session keys), making it nearly as efficient as stateful?
Saurabh Agrawal that is correct. JWT is better than session keys, JWTs has signature in them allowing server to quickly verify it Without hitting the db. They are also still stateless because the client sends the jwt with each request. So you can restart the server and the client can hit completely a different server and still be served .
With session keys (what we explained in this video we have to verify the key by hitting the db)
Good question
Check out my JWT video JSON Web Token with NodeJS & Postgres Crash Course
ua-cam.com/video/T0k-3Ze4NLo/v-deo.html
Good. I think the same way a token is stored in the DB and queried by all instances of system, a sessionID (localStorage of any kind of native app local storage) can be used with the same results in computing cost. The main PROs of using stateless is regarding to JWT, a way to validate tokens by the information it contains itself and not by querying the DB. Sessions ID and Tokens can be managed the same in backend and frontend, but for exposure to any client/platform, JWT is the way to go right now also because its granularity about granting specific permissions. Thank you.
Such a great explanation! Thanks
good info. but it is actually possible to scale horizontally with stateful applications. I have done this in the past using a load balancer and sticky sessions. You can use sticky sessions to redirect the user requests to the same server that already has the session for the user.
Correct, you can scale stateful apps for sure with clever logic. However if that server to which the sticky session is locked on is restarted the application breaks.
What if we use Sticky connections in the load balancer ? Could it work properly if we scale Stateful applications horizontally ? Putting aside eventually crashes on servers that may not occur frequently.
Augusto Napuri that would work and would scale nicely. As you said if the server crash the client will have to login again since they will hit a new server.
Another disadvantage is if the server is overloaded and latency dropped as a result its difficult to move client to another server in a smooth manner.
Just amazing explanation bro!
But how do you store Alice's token without changing state? Wouldn't the difference be that the state changes on the client instead of the server?
luls good question! The client is transferring the state (token) all the time with each request and the server does not hold the state it merely connects to the database to check if the token is ok.
So if you truly think about it our entire system is still stateful by the way because we are storing the token (state) in the database but our application (hosted on server1/2) is stateless. The client is of course stateful because it holds the token.
Any layer that holds a state in its memory or disk is called stateful. While our backend app doesnt hold anything so if you restart it we can still work just fine because the client will always send the state to us. Thus the state transfer in REST.
Hope that helps :)
Sir, I am just about to start my second year at university, with an assignment to develop a web application and, after watching your videos, I believe I have a higher status than God. XD Jokes aside, honestly, thank you so much!!!
Zacharias King thanks Zach for the love and comment! Best of luck in your assignment!! Take a look at the other content of the channel, more cool stuff for you! Cheers
I enjoyed it, simple and clear explanation.,
Man, you are a perfectionist! Prepare the slides beforehand! It drove me crazy, watching you constantly resizing and moving stuff around!!!
But in a stateful app, the server still has to use cookies to authenticate or recognize the user, and when you meant we have to hit the db every time to query for the token, it sounds pretty bad, but isn't that information also cached somewhere to tie in with the cookie expiry, because if were to really look at it sometime a single page might send around 20 to 30 requests to get different information from a stateless backend(REST) but it cannot afford to authenticate the user 20 times right ?
15 mins of awesome ! Thank you !
It looks like the only difference is: Stateful: save the session info in service. Stateless: save the session info in 3rd party component, say database
What if we just store the stateful session info in a common distributed cache (in the first example)?
Load Balancers can redirect the user to the same server usually by using a cookie, otherwise LB would be useless
loved it. You made it clear to me. Thanks and yes, I subscribed.
Mukesh Singh Rawat thanks Mukesh! Glad I could help and welcome to the community!! Enjoy the content
I finally understand this! Thank you
Nicely explained in simple way... with real time login application use case scenario.....
Glad you enjoyed it! I made another video about how Amazon Alexa is stateless maybe you will enjoy that as well ua-cam.com/video/zhwMv5RxGew/v-deo.html
For the stateful example, if the client uses a cookie and the server stores a session token in DB, I think we can solve the problem of horizontal expansion?
Thanks Yuan, yeah if you kept the session in the server memory and also stored it in DB you will be able to scale.
I am assuming you will validate the session again the server memory first? (Some sort of cached data structure that tells you who is the user )
If the session id doesn’t exist in the server you can hit the DB and cache, if it does than all good.
sure works, the only limitations now is that if the session is now invalided (manually removed from the database) you need to also write some logic to invalidate the session from each server that cached the session. There are ways to solve that but you just need to be aware.. another stateless approach is to use JWT (check out my video on JWT if you are interested to learn more on the topic)
@@hnasr Got it. Thanks for the detailed explanation! And also thanks for all the videos, I surely learned a lot!
Geniussssssssssssssssssssssssss! Excellent Explanation Hussien, the best! Thank you so so much :)
so state vs stateless is just session vs token? What's does the "state transfer" in REST have to do with it though?
Very well made. Thanks for the explanation.
very well explaining, thank you man !
Amaaaaaaaazzzzziiiiiiinnnnngg. I think we can also use some cache like Redis, to do this soft authentication.
I mean what part, those 203 people disliked this awesome video , did not understand... Loosers
Authentication is an excellent example of just how silly webdev can get.
In a statefull application you logon to server 1, that server checks your credentials, records your loggerd-in status and you get a cookie that refers to that state. This is considered bad because server-2 needs to share some storage with server-1 to know if the cookie is valid and who it belongs to.
In "stateless" application you logon to server-1, that server checks your credentials and gives you a cookie that that server-2 can also verify as being authentic (like a JWT). The problem is that the state that is received by server-2 *MUST* be verified against the same database that server-1 used to create it, for the simple reason that the user may have been denied access since the token was created. You *MUST* verify.
So, statelessness does not really change anything from a serverload perspective,it just sneds bigger tokens because you need to use something like JWT. The hardware on the server side is identical, withidenticalproblems that, let's face it, are not really problems at all. Replicating data among databases is not an issueunless you are a gigantic websitewith hundreds of servers but by then you will have heard of sharding.
What about storing the session in redis, and all the server instances reaching looking for the session. I mean redis is a cache as well but it can persists
Sure that works, in that case your app will be stateless but the whole system remains stateful
Cool video. But got me thinking a bit. I am not sure I am completely with you in here. Please correct me if this is wrong: the difference in your examples is only the fact that in the 1st example you cache the value in server1 while on the 2nd example you don't cache the values, you always check the token against the db. Isn't a more 'stateless' example a scenario where you can rely on the information on the token to do the validation (jwt)?
João Salgado that is correct, when I mention stateless and stateful in the video I was referring to the application that is hosted on the servers. So in the first case my application is stateful (cant scale) and in the second case my application is stateless. However the entire system still has a state which as you mentioned its in a database. Building a real stateless “system” is very hard because most of the time you probably need to store your state somewhere. Thanks for your comment!
Great Vids and Great explanation , Love From Indonesia
Steven Humam thanks! Much love to all my Indonesian subs you guys rock!
What about using JWT to avoid DB calls at every request for validating the token?
This keeps the stateless architecture intact by also covering its downsides. Doesn't it?
True saves you couple of db hits but there are limitations to JWT that I talked about here
ua-cam.com/video/T0k-3Ze4NLo/v-deo.html
i think i got it, in a nutshel, stateful means that the server store information about that "session", but in the stateless the token doesnt have to be saved also? gonna read more about it, great video btw!
Thiago Dias That make sense, you can watch the new video about the same topic with examples. ua-cam.com/video/nhwZn6v5vT0/v-deo.html thanks for your comment
Excellent explanation! Good job.
best teacher man.
this video is best played at 1.5x speed to make him sound like he's talking regularly.
Oh, man...Wonderful!
why store the token in the database? isn't the point so that you can decrypt it using some secret stored in an environment variable so that you can verify that the token came from you (and not tampered with) and thus you don't have to query the database to give access to protected resources?
Somebody please help me understand this concept. If we have a stateful application and are using load balancing with consistent hashing then that would solve the problem of failed viewProfile request or not?
That's some cool explanation.
You are one of the best I've ever followed but I think you've missed something in this video.
The matter is not about where to store the data (in memory or in DB or in a file or whatever the place is) !! It's all about, DO YOU STORE IT OR NOT for next requests handling purposes?
If the server can process a request without relying on an earlier request then it's STATELESS. If the server needs information from previous requests to be stored (in memory or DB) in order to process the current request then it's STATEFUL.
REST would help to understand that since it's stateless. It sends the STATE of RESOURCE (which could be a USER) within the request every time without saying: "Why I should send it every time. why not just set it in a DB and things will be fine and stateless! 😅"
I think, as a monolith application, no way to not be stateful but as a microservice, you could have one service that is stateful (for authentication and authorization) and other services are just stateless (pure business logic and the state of that logic will be sent through REST or whatever).
What do you think? Do I have a point of view?
Hi, I still don't understand the stateless application. At first, the user sends a request to Load Balancer. This request may be passed into server 1. Server 1 sends back a token to the client. However, how can the server 2 still understand the request from the client? The server 2 doesn't know the token that belongs to a certain client?. Correct me If I am wrong. Could you explain this process again. Thank you
Because Server 2 will query the database to understand if the token is valid. so the application doesn't store the state in itself but is stored somewhere else (the database) that is why we say the application is stateless but the system remain stateful.
@@hnasr Thank you so much for your great explanation. Now I fully understand the stateful and stateless system. In summary, the stateful means the Server stores the information of the user by itself. Stateless means the server doesn't store the information of the user, but I still can understand the request is valid or not based on the token (which is saved somewhere).
Really beautiful explanation !! Thank you so much
You are a great teacher many thanks!
I try! thank you so much for your lovely comment
Hello Sir, I am fan of your video. I have one question if I have to use the stateful service there is multiple servers how do we sync the information across different machines?
Sagar Sawant good question, the common architecture pattern is to use a centralized caching node such ad redis
@@hnasr thank you for prompt response. I am big fan of your video's
What's the difference between a token and a cookie? Why is a cookie considered stateful and a token stateless? Is there no record of the token server side? By what process is it authenticated then?
Explanation is good. Thank you .. Would you mind clarifying my doubt ? is this concept used only for a Web applications ? or any Services ? Sorry if its a dumb question.. As I am new to the dev, curious to know. :)
Jyotsna Doddi good question! No it applies to any kind of service that is consumed by many clients. Whether this is on HTTP or raw TCP or any other protocol. As long as the service is consumed via a client, each request should be treated independently from previous requests.. hope that helps :)
IGeometry wow you are quick in responding ... thank you for clarifying...
Jyotsna Doddi :) i try my best ! Checkout the other content in this channel if your new software engineer