In this note, we’ll be covering:

Keep your mobile away, bring a huge bottle of water, remove all distractions, and let’s f*king GO!


What if we have 2 servers, and a load balancer which alternatively sends requests to either server?

image.png

A user adds an item to their cart that is stored in-memory (RAM) of the first server, but upon refreshing, the request is sent to the second server and user gets an empty cart.

<aside> 💡

How to solve this issue?

</aside>

The mistake the developer made, is storing the "state" on a single node.

image.png

So instead of your server gatekeeping the cart items in it's RAM, everyone shares a central lightening-fast cache database.

image.png

And congratulations! You just unlocked 2 new items:

Stateless Architecture

Because no “state” is being stored on a single server. By offloading state to an external, shared databases, we can effortlessly horizontally scale our applications, as much as we’d like to.