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
  • НаукаНаука

Комментарии • 315

  • @nikhilbalwani5556
    @nikhilbalwani5556 4 года назад +155

    If you were my professor, I would be ready to sit in your lecture for hours. Beautiful explanation

    • @hnasr
      @hnasr  4 года назад +9

      Nikhil Balwani im humbled ❤️ thanks

    • @ShoeibShargo
      @ShoeibShargo 2 года назад +4

      If he were my professor, I would be sitting at FAANG now.

    • @adamgontiersa78
      @adamgontiersa78 Год назад

      And you would land any job you want, he exolains concerts with simplicity and efficiency

  • @zencollector
    @zencollector 3 года назад +9

    Even 3 years later this explanation is one of the best on the web. Thanks a bunch mate!

  • @anonymous.youtuber
    @anonymous.youtuber 4 года назад +24

    Man am I glad I found someone that really knows how to really explain something. Great video ! 👍🙋‍♀️

    • @hnasr
      @hnasr  4 года назад +4

      Thank you Claire 🙏 I am glad you enjoyed the content and found it helpful

  • @John845
    @John845 3 года назад +3

    Been programming over a year and never realized the correlation between REST and Stateless. Mind = blown. THANK YOU.

  • @vishwaskaupvijayananda3900
    @vishwaskaupvijayananda3900 4 года назад +8

    This video makes a lot of other web app concepts so much more clearer. Thanks a mil!

  • @matthewspiteri482
    @matthewspiteri482 5 лет назад +57

    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 :)

    • @hnasr
      @hnasr  5 лет назад +7

      Matthew Spiteri Thank you so much for your wonderful comment. Glad to see fellow software developers here. Best of luck !

  • @hnasr
    @hnasr  5 лет назад +4

    Watch the new 2019 video Stateless vs Stateful python 🐍 application code examples ruclips.net/video/nhwZn6v5vT0/видео.html

  • @mollycrime
    @mollycrime 4 года назад +6

    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!

    • @hnasr
      @hnasr  4 года назад +1

      mollycrime Thanks! I try to give examples where I can from my personal experience working with a technology. Appreciate it!

  • @ruixue6955
    @ruixue6955 4 года назад +54

    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

    • @deepak3303
      @deepak3303 3 года назад

      wow, indented sub-chapters. RUclips should support MD for comments. 🔥🔥

  • @shreysom2060
    @shreysom2060 3 года назад +1

    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

  • @staj
    @staj 4 года назад +2

    Brilliantly and Concisely explained! Thanks a Lot HN!

  • @hnasr
    @hnasr  5 лет назад

    Check out my new video about stateful apps ruclips.net/video/EKCM1oQQrCM/видео.html

  • @ack377
    @ack377 3 года назад

    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

  • @srinidhikulkarni1962
    @srinidhikulkarni1962 2 года назад

    This was amazing man!! Loved the way you impart things to the viewers!! High Five!

  • @Xardas_
    @Xardas_ 2 года назад

    It's no longer over my head. Thanks

  • @claushellsing
    @claushellsing 4 года назад +3

    I'm on a marathon of your videos man. Awesome content

    • @hnasr
      @hnasr  4 года назад

      Enjoy 😊

  • @hnasr
    @hnasr  2 года назад

    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

  • @stephaniecrispin674
    @stephaniecrispin674 Год назад

    This is the best tutorial I have ever seen in my life. I'm awed!.

  • @potomskazhu
    @potomskazhu 2 года назад

    dude just thanks, really helped to quickly get a grasp of it

  • @JoseBlanquicetM
    @JoseBlanquicetM 3 года назад

    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!

  • @tuck582
    @tuck582 5 лет назад

    Doesn't something like "Reliable Collections" solve the scaling issue for stateful (at least for Service Fabric devs)?

  • @potaraju92
    @potaraju92 4 месяца назад

    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.

  • @samuelshoyemi3751
    @samuelshoyemi3751 3 года назад

    Plain and simple. Thanks Hussein

  • @JS-rz5gx
    @JS-rz5gx 2 года назад

    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!

  • @emjaytripleo
    @emjaytripleo 2 года назад

    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 ?

  • @subramanian121
    @subramanian121 2 года назад +1

    Great video Hussein. Thanks for the example.

  • @hnasr
    @hnasr  5 лет назад +27

    Stateful Example: 1:10
    Stateless Example: 8:30
    Stateless vs Stateful pros and cons: 13:30

    • @sasg87962
      @sasg87962 5 лет назад

      ونعم ابوعلي

  • @harrygeorgiou8518
    @harrygeorgiou8518 3 года назад +1

    Very well explained! keep the videos coming!

  • @romanleca4969
    @romanleca4969 5 лет назад +6

    This is outrageously good. Thank you, mate!

  • @shubhambatham49
    @shubhambatham49 4 года назад +10

    Sending a long ass token of appreciation all the way from India !! Great & Interesting explanation.Thank you !!

    • @hnasr
      @hnasr  4 года назад +12

      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!!

  • @ducdatnguyen9251
    @ducdatnguyen9251 3 года назад +1

    very well explaining, thank you man !

  • @parvezmulla3324
    @parvezmulla3324 3 года назад +1

    your channel is a gem!

  • @mariusm5187
    @mariusm5187 4 года назад +1

    Very helpful video, thank you!

  • @natalieschulz7896
    @natalieschulz7896 6 лет назад +11

    Awesome Video ! Glad I found this - I am VERY NEW to Web Dev and this broke this complex subject down easily :) THANKS

    • @hnasr
      @hnasr  6 лет назад +1

      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 :)

  • @cw5948
    @cw5948 4 года назад +1

    Excellent explanation! Good job.

  • @tranphunguyen7044
    @tranphunguyen7044 2 года назад

    very clear and easy to understand by the excellent explanation. Thank you so much.

  • @mukulrana1616
    @mukulrana1616 2 года назад

    This is the best explaination on youtube

  • @vidyakrishnan1757
    @vidyakrishnan1757 2 года назад

    15 mins of awesome ! Thank you !

  • @augustonapuri3152
    @augustonapuri3152 4 года назад

    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.

    • @hnasr
      @hnasr  4 года назад +1

      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.

  • @viniciosantos
    @viniciosantos 2 года назад

    I finally understand this! Thank you

  • @0xRei
    @0xRei 3 года назад

    just learned about load balancers too bless you ser!!!!!!!!

  • @user-dd2ux8wb4c
    @user-dd2ux8wb4c 2 года назад

    What if we just store the stateful session info in a common distributed cache (in the first example)?

  • @aminegh8725
    @aminegh8725 2 месяца назад

    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 ❤❤❤

  • @EnochMaheshsilva
    @EnochMaheshsilva 2 года назад

    Wow ! Simply an amazing explanation, now only I understand what it means 'State Transfer' in ReST, thanks, keep explaining.

  • @aatifnazar8203
    @aatifnazar8203 3 года назад

    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?

  • @migueljurado6783
    @migueljurado6783 2 года назад

    Just amazing explanation bro!

  • @TexAli
    @TexAli 4 года назад +1

    Thank you for a great explanation

  • @ademtepe2855
    @ademtepe2855 3 года назад

    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?

  • @masonthompson8332
    @masonthompson8332 4 года назад

    Nice work, appreciate the overview.

  • @onlyamitava
    @onlyamitava 3 года назад +1

    You explained nicely.. Thanks a lot.

  • @pradeepramola8900
    @pradeepramola8900 2 года назад

    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 )

  • @mcuve105
    @mcuve105 3 года назад

    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

    • @hnasr
      @hnasr  3 года назад +1

      Sure that works, in that case your app will be stateless but the whole system remains stateful

  • @ayazahamed8254
    @ayazahamed8254 Год назад

    Very well explained. Good Job Bro. It clears my concept for stateful and stateless 🌹

  • @sarvesh81s
    @sarvesh81s 6 лет назад +1

    Good Explanation..Thank you

  • @noranhany8213
    @noranhany8213 2 года назад

    Thank you for simple explanation

  • @arioafrashteh6767
    @arioafrashteh6767 Год назад

    If you replacte the DB and using the same DB replications for the same Microservice replication the statefull-problem will be solved?

  • @WaldoTheWombat
    @WaldoTheWombat Месяц назад

    so state vs stateless is just session vs token? What's does the "state transfer" in REST have to do with it though?

  • @kevinmontalvoflores6614
    @kevinmontalvoflores6614 5 лет назад +3

    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

    • @hnasr
      @hnasr  5 лет назад +1

      Kevin Montalvo Flores exactly well said. It is a trade off that you as a software engineer/architect make.

  • @verma-kunal
    @verma-kunal 2 года назад

    Really beautiful explanation !! Thank you so much

  • @joshuawalker7375
    @joshuawalker7375 Год назад

    Very well made. Thanks for the explanation.

  • @Saurabhandsonu1994
    @Saurabhandsonu1994 5 лет назад +1

    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?

    • @hnasr
      @hnasr  5 лет назад +2

      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

    • @hnasr
      @hnasr  4 года назад

      Check out my JWT video JSON Web Token with NodeJS & Postgres Crash Course
      ruclips.net/video/T0k-3Ze4NLo/видео.html

  • @mukeshsinghrawat474
    @mukeshsinghrawat474 4 года назад +1

    loved it. You made it clear to me. Thanks and yes, I subscribed.

    • @hnasr
      @hnasr  4 года назад

      Mukesh Singh Rawat thanks Mukesh! Glad I could help and welcome to the community!! Enjoy the content

  • @romantsyupryk3009
    @romantsyupryk3009 4 года назад

    Thanks so much for this video tutorial.

  • @othmaneibrahimi6026
    @othmaneibrahimi6026 3 года назад

    Very well explained, thank you ;)

  • @batoolal-sulh2165
    @batoolal-sulh2165 4 года назад +1

    thank you so much that's so helpful

  • @sumitsharma5537
    @sumitsharma5537 5 лет назад +1

    Interesting explanation!

  • @priyamvashi2187
    @priyamvashi2187 5 лет назад +1

    Nice explanation ..Thank you

  • @denishsubedi3180
    @denishsubedi3180 2 года назад

    Very good explanation, i want you to teach a whole class of everything i want to learn!!!!

  • @souravskr
    @souravskr 3 года назад

    It is worthy of investing 14 minutes of your life. Thanks Hussein

  • @NAVNEET549
    @NAVNEET549 2 года назад

    That's some cool explanation.

  • @ChHammadVEVO
    @ChHammadVEVO 3 года назад +1

    Oh, man...Wonderful!

  • @vinayaksharma-ys3ip
    @vinayaksharma-ys3ip 2 года назад

    Great video!!! Thanks a ton Sir!

  • @fajartris
    @fajartris 3 года назад

    I enjoyed it, simple and clear explanation.,

  • @girishtiwari79
    @girishtiwari79 4 года назад +1

    Wonderful explanation

  • @aalaptube
    @aalaptube 3 года назад

    How does the server know call to viewProfile was by Bob and not John?

  • @hantzleyaudate7697
    @hantzleyaudate7697 6 лет назад +5

    You’re the man! Great video my dude, the examples were spot on. Are you independent or do you work at a software company?

    • @hnasr
      @hnasr  6 лет назад +2

      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!

  • @arijitnagchowdhury3740
    @arijitnagchowdhury3740 5 лет назад +1

    Thanks for the video -- this is helpful .
    Is oAuth stateless since there we are using token ?

    • @hnasr
      @hnasr  5 лет назад +2

      Arijit Nag Chowdhury with OAuth2 yes the protocol became easier at achieving statelessness using JWT (Json Web Token) :)

  • @CoolBishop1997
    @CoolBishop1997 5 лет назад +1

    outrageously good l:D like it ! best way to spend my component afternoon at work on something ludicrous lol

    • @hnasr
      @hnasr  5 лет назад

      Imad Amahmid haha glad I could provide education and entertainment thanks for watching

  • @lolokj6848
    @lolokj6848 4 года назад +1

    Best explain ever..Many thanks

    • @hnasr
      @hnasr  4 года назад

      🙏

  • @maartenvissers283
    @maartenvissers283 3 года назад

    Does stateful/stateless only concern authenticating users?

  • @emadelhori496
    @emadelhori496 2 года назад

    this is amazing channel

  • @luls9000
    @luls9000 5 лет назад +1

    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?

    • @hnasr
      @hnasr  5 лет назад +1

      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 :)

  • @tenzl
    @tenzl Год назад

    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?

  • @KrishAgrawal
    @KrishAgrawal 4 года назад +6

    Sir, you really explained well. I am a 9th-grade student and I was completely able to understand what you meant.

  • @gabriel-quintiliano
    @gabriel-quintiliano 5 месяцев назад

    Great video!

  • @NagendraBabutoecrusher
    @NagendraBabutoecrusher 6 лет назад +2

    Good Explanation.. keep up the good work :)

    • @hnasr
      @hnasr  6 лет назад

      Nagendra Babu thanks dude! Appreciate it

  • @mohinimadavi5870
    @mohinimadavi5870 3 года назад +1

    Thanks a lot! It was crystal and clear explanation. Easy to understand. Subscribing you!

    • @hnasr
      @hnasr  3 года назад

      Thanks for the sub! appreciate you dear enjoy the content

  • @mukulkopulwar
    @mukulkopulwar Год назад

    Thank you for this

  • @OhWord88
    @OhWord88 4 года назад +1

    Your explanation made me feel really "cool" and "lit" because I was able to understand this 😂 Definitely giving this video a like! 👍

    • @hnasr
      @hnasr  4 года назад

      Jordan Theisen Jordan you are cool and definitely lit 🔥 thanks for your comment!

  • @nageshsingh2330
    @nageshsingh2330 Год назад

    I am from Electrical background still understand it, nice explanation with diagram.

  • @psstream889
    @psstream889 Год назад

    Your explanation is far more better than my college lecturer

  • @pswalia2u
    @pswalia2u 3 года назад +1

    Great explanatio I think nowadays JWT solved the problem of querying db each time we make request.🤔

  • @muhammadinshal6216
    @muhammadinshal6216 3 года назад

    Just logged in to comment a word of appreciation. Glad I found this channel. Beautiful content

    • @hnasr
      @hnasr  3 года назад

      Appreciate it ❤️❤️

  • @igrok878
    @igrok878 Год назад

    so the difference is whether you store the state on the server or in database?..

  • @RohitPatnala
    @RohitPatnala 2 года назад

    Such a cool teacher! :D

  • @sagarshekhar6296
    @sagarshekhar6296 4 года назад

    Excellent explanation Hussein.....

  • @stevenhumam2589
    @stevenhumam2589 5 лет назад +1

    Great Vids and Great explanation , Love From Indonesia

    • @hnasr
      @hnasr  5 лет назад +1

      Steven Humam thanks! Much love to all my Indonesian subs you guys rock!

  • @ylu423
    @ylu423 4 года назад

    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?

    • @hnasr
      @hnasr  4 года назад

      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)

    • @ylu423
      @ylu423 4 года назад

      @@hnasr Got it. Thanks for the detailed explanation! And also thanks for all the videos, I surely learned a lot!

  • @naderreda2020
    @naderreda2020 2 года назад

    Great..... Thank you

  • @MASTERISHABH
    @MASTERISHABH 3 года назад

    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?

    • @hnasr
      @hnasr  3 года назад

      True saves you couple of db hits but there are limitations to JWT that I talked about here
      ruclips.net/video/T0k-3Ze4NLo/видео.html