Designing Simple Systems
Designing Simple Systems: The Login System
Let’s put everything we’ve learned together and design a simple, common system: The User Login System.
The Goal:
A user should be able to enter their username and password and be logged into the application.
Step 1: The Components
- The Client: The browser where the user types their username and password.
- The Server: The application running the “Login” code.
- The Database: Where the user’s username and (hashed) password are stored.
- The Load Balancer: Distributes traffic if we have many servers.
Step 2: The Flow
- Request: The client sends a
POSTrequest to the Load Balancer with the username and password. - Routing: The Load Balancer sends the request to one of our servers.
- Authentication: The server asks the database for the user’s record.
- Verification: The server compares the password the user sent with the one in the database.
- Response: If they match, the server sends back a “Success” message and a
200 OKstatus code.
Simple Diagram
[ User ]
|
v
[ Load Balancer ]
|
v
[ Login Server ]
/ \
/ \
v v
[ Database ] [ Auth Cache ]
(Passwords) (Sessions)
Considerations for Scale
- Is it fast?: We might use a Cache (like Redis) to store user sessions so we don’t have to check the database every time.
- Is it reliable?: If the database goes down, we need a Replica (a backup) ready to take over.
- Is it secure?: We never store passwords in “plain text”; we always “hash” them first.
Practice Problem
Try to draw a simple diagram for a “To-Do List” application. What components would you need?