Stateful vs Stateless Applications (Explained by Example)
HTML-код
- Опубликовано: 24 июл 2024
- If you ever wondered the difference between stateless and stateful applications, REST, horizontal scaling versus vertical scaling? We tackle those in a small example. Hope you guys enjoy this quick video. We explain the advantages and disadvantages of each application.
0:00 Intro
1:14 Stateful Application
8:40 Stateless Application
Online diagram tool used in this video: Http://www.gliffy.com
Checkout the rest of the content for more software engineering topics by example.
🏭 Software Architecture Videos
• Software Architecture
💾 Database Engineering Videos
• Database Engineering
🛰 Network Engineering Videos
• Network Engineering
🏰 Load Balancing and Proxies Videos
• Proxies
🐘 Postgres Videos
• PostgresSQL
🧮 Programming Pattern Videos
• Programming Patterns
🛡 Web Security Videos
• Web Security
🦠 HTTP Videos
• HTTP
🐍 Python Videos
• Python by Example
🔆 Javascript Videos
• Javascript by Example
Stay Awesome
-Hussein Nasser
www.husseinnasser.com Наука
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!
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
Been programming over a year and never realized the correlation between REST and Stateless. Mind = blown. THANK YOU.
This video makes a lot of other web app concepts so much more clearer. Thanks a mil!
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 !
Watch the new 2019 video Stateless vs Stateful python 🐍 application code examples ruclips.net/video/nhwZn6v5vT0/видео.html
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!
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. RUclips should support MD for comments. 🔥🔥
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
Brilliantly and Concisely explained! Thanks a Lot HN!
Check out my new video about stateful apps ruclips.net/video/EKCM1oQQrCM/видео.html
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
This was amazing man!! Loved the way you impart things to the viewers!! High Five!
It's no longer over my head. Thanks
I'm on a marathon of your videos man. Awesome content
Enjoy 😊
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
This is the best tutorial I have ever seen in my life. I'm awed!.
dude just thanks, really helped to quickly get a grasp of it
Hi Hussein, thanks for your channel. I really appreciate the work you are doing on this.
For this video, I would like to know if in the case of stateful app, is it possible to use an "intelligent" LB such that the requests for a given user go always to the same server. In this way we can also have a cache into the servers for their users given that we know they will always use the same one? Something like consistent hashing?
Thanks!
Doesn't something like "Reliable Collections" solve the scaling issue for stateful (at least for Service Fabric devs)?
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.
Plain and simple. Thanks Hussein
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!
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 ?
Great video Hussein. Thanks for the example.
Stateful Example: 1:10
Stateless Example: 8:30
Stateless vs Stateful pros and cons: 13:30
ونعم ابوعلي
Very well explained! keep the videos coming!
This is outrageously good. Thank you, mate!
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!!
very well explaining, thank you man !
your channel is a gem!
Very helpful video, thank you!
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 :)
Excellent explanation! Good job.
very clear and easy to understand by the excellent explanation. Thank you so much.
This is the best explaination on youtube
15 mins of awesome ! Thank you !
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.
I finally understand this! Thank you
just learned about load balancers too bless you ser!!!!!!!!
What if we just store the stateful session info in a common distributed cache (in the first example)?
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 ❤❤❤
Wow ! Simply an amazing explanation, now only I understand what it means 'State Transfer' in ReST, thanks, keep explaining.
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?
Just amazing explanation bro!
Thank you for a great explanation
I know stateful but I'm new to stateless concept. I have a question:
What if I keep session data in a shared service (like Redis) and all of the servers can reach it?
Is it possible and if it is, isn't stateful a better choice than stateless?
Nice work, appreciate the overview.
You explained nicely.. Thanks a lot.
Hey , thanks for amazing explanation ! just had a question does token gets stored in database (how it gets generated )and how does it gets expired (when one doesn't login )
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
Very well explained. Good Job Bro. It clears my concept for stateful and stateless 🌹
Good Explanation..Thank you
Thank you for simple explanation
If you replacte the DB and using the same DB replications for the same Microservice replication the statefull-problem will be solved?
so state vs stateless is just session vs token? What's does the "state transfer" in REST have to do with it though?
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.
Really beautiful explanation !! Thank you so much
Very well made. Thanks for the explanation.
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
ruclips.net/video/T0k-3Ze4NLo/видео.html
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
Thanks so much for this video tutorial.
Very well explained, thank you ;)
thank you so much that's so helpful
Interesting explanation!
Nice explanation ..Thank you
Very good explanation, i want you to teach a whole class of everything i want to learn!!!!
It is worthy of investing 14 minutes of your life. Thanks Hussein
That's some cool explanation.
Oh, man...Wonderful!
Great video!!! Thanks a ton Sir!
I enjoyed it, simple and clear explanation.,
Wonderful explanation
How does the server know call to viewProfile was by Bob and not John?
You’re the man! Great video my dude, the examples were spot on. Are you independent or do you work at a software company?
Hantzley Audate thanks buddy for the nice comment! I work at a software company called Esri. I do these videos on the side :) glad you like the content!
Thanks for the video -- this is helpful .
Is oAuth stateless since there we are using token ?
Arijit Nag Chowdhury with OAuth2 yes the protocol became easier at achieving statelessness using JWT (Json Web Token) :)
outrageously good l:D like it ! best way to spend my component afternoon at work on something ludicrous lol
Imad Amahmid haha glad I could provide education and entertainment thanks for watching
Best explain ever..Many thanks
🙏
Does stateful/stateless only concern authenticating users?
this is amazing channel
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 :)
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?
Sir, you really explained well. I am a 9th-grade student and I was completely able to understand what you meant.
Great video!
Good Explanation.. keep up the good work :)
Nagendra Babu thanks dude! Appreciate it
Thanks a lot! It was crystal and clear explanation. Easy to understand. Subscribing you!
Thanks for the sub! appreciate you dear enjoy the content
Thank you for this
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!
I am from Electrical background still understand it, nice explanation with diagram.
Your explanation is far more better than my college lecturer
Great explanatio I think nowadays JWT solved the problem of querying db each time we make request.🤔
Just logged in to comment a word of appreciation. Glad I found this channel. Beautiful content
Appreciate it ❤️❤️
so the difference is whether you store the state on the server or in database?..
Such a cool teacher! :D
Excellent explanation Hussein.....
Great Vids and Great explanation , Love From Indonesia
Steven Humam thanks! Much love to all my Indonesian subs you guys rock!
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!
Great..... Thank you
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
ruclips.net/video/T0k-3Ze4NLo/видео.html