Day7 in System Designing
basic · System Designing
The Client-Server Model is the foundational architecture of the modern internet. It is a distributed application structure that partitions tasks or workloads between the providers of a resource or service, called servers , and service requesters, called clients . 1. The Core Components A. The Client The client is the end-user gateway. It does not host the primary data or application logic; instead, it requests it. Examples: A web browser (Chrome, Safari), a mobile app (Instagram, Spotify), or a command-line tool (cURL). Role: Formats user actions into requests, sends them over a network, and renders the server's response into a user-friendly interface. B. The Server The server is a centralized machine (or cluster of machines) that is always on, waiting for incoming requests. Examples: An Express.js backend, an AWS EC2 instance, or a cloud database. Role: Listens on a specific network port, validates credentials, processes business logic, queries databases, and sends back the requested data. C. The Network (The Request-Response Cycle) Clients and servers communicate over a computer network (like the internet) using established protocols (like HTTP, HTTPS, or WebSockets). The Request: The client sends an explicit message (e.g., GET /profile ). The Processing: The server receives the message, executes code, and fetches data. The Response: The server sends data back (e.g., a status code 200 OK along with a JSON payload or HTML file). 2. Key Characteristics Centralized Control: All resources, security permissions, and data access are managed on the server side. If you need to fix a bug or update data, you update the server, and every client instantly gets the new version. Asymmetry: The relationship is uneven. The client always initiates the communication. The server cannot spontaneously send data to a standard client without being asked first (unless modern persistent protocols like WebSockets are implemented). Decoupling: The client doesn't need to know how the server's database works; it only needs to know the API endpoint. The server doesn't care if the client is an iPhone or a Windows laptop, as long as the request is formatted correctly. 3. Client-Server vs. Peer-to-Peer (P2P) In a P2P network, there is no central server . Each device (peer) can both request and provide resources. How it works: A peer requests a file or resource. Other peers that have it send it directly. Multiple peers can share simultaneously. When moving into system design, it helps to contrast this model with its primary alternative: Feature Client-Server Model Peer-to-Peer (P2P) Model Architecture Centralized Decentralized Nodes Distinct roles (Client requests, Server serves) Every node acts as both a client and a server Scaling Scaled by upgrading servers (Vertical/Horizontal) Scaled automatically as more peers join the network Examples Netflix, Google, standard web apps BitTorrent, Blockchain networks 4. Evolution of the Model (Tiers) As systems grow from simple scripts to enterprise platforms, the server side is broken down into "Tiers" to handle scale: A. 2-Tier Architecture The client talks directly to the database. Verdict: Fine for simple local software, but terrible for web security because exposing database credentials to the client is a massive risk. B. 3-Tier Architecture (The Industry Standard) The structure used in almost every production application, including standard MERN stacks: Presentation Tier (Client): The UI layer (React, HTML/CSS). Application Tier (Server): The business logic (Node.js/Express backend). Data Tier (Database): The storage layer (MongoDB, PostgreSQL). 5. Designing for System Scale To prevent the server from crashing, you introduce system components we discussed earlier: Load Balancers to distribute the client requests across a pool of application servers. Caches (like Redis) so the application tier doesn't choke the data tier with repetitive queries. Content Delivery Networks (CDNs) to cache static assets (images, frontend code) physically closer to the client, taking the load off your primary servers entirely.