Building Blocks of Software: System Design Patterns.

programmedraj
4 min readSep 5, 2024

--

Photo by Boitumelo on Unsplash

1. Authentication vs. Authorization

Authentication: The process of verifying a user’s identity.

Examples:- Logging in with Facebook or Google, Single Sign-On (SSO) allows users to log in once and access multiple applications seamlessly.

Authorization: Determines, what actions a user is permitted to perform.

Examples:- Permissions given to users to like or comment on a post.

2. Caching Strategies

Caching improves system performance by storing frequently accessed data.

👉 Different caching strategies:-

  • Write-through caching ensures consistency and low latency by writing data to both cache and storage simultaneously.
  • Write-back caching initially writes data to the cache and asynchronously updates the storage, which can lead to data loss but offers faster performance.
  • Write-around caching bypasses the cache and writes directly to storage, reducing cache load but increasing latency for less frequently accessed data.

3. CAP Theorem

It states that in a distributed system you once only guarantee 2/3 properties: Consistency, Availability, and Partition Tolerance.

What does each term guarantee?

  • Consistency: Every read must get the most recent write.
  • Availability: Requests must receive a response, if not the most recent data.
  • Partition Tolerance: If network is partitioned, system must continue to work.
Visualize the CAP theorem
  • CA (Consistency and Availability): No partition tolerance.
  • CP (Consistency and Partition Tolerance): Possible downtime.
  • AP (Availability and Partition Tolerance): Eventual consistency.

4. Load Balancers

Load balancers distribute traffic across multiple servers to prevent overload.

  • DNS-based: Uses DNS to balance load.
  • Hardware-based: Utilizes physical devices.
  • Software-based: Employs solutions like Nginx and AWS ELB.

👉 Common algorithms include Round-Robin, Weighted Round-Robin, IP Hash, and Least Connections.

5. Proxies

Reverse Proxy: Acts on behalf of servers, providing load balancing and security while hiding server identities. It includes AWS ELB and Nginx.

Forward Proxy: Acts on behalf of clients, used for caching and access control, while hiding client IP addresses.

Forward proxy vs Reverse proxy

6. Hashing

Widely used algorithms like MD5 and SHA used for data integrity and security.

  • Consistent hashing ensures that the addition or removal of servers doesn’t significantly affect the system.
  • Rendezvous hashing calculates hashes with all servers to select the one with the highest value.

7. REST and Alternative Protocols

  • REST: A stateless protocol using HTTP methods like GET, POST, PUT, and DELETE.
  • gRPC: A high-performance RPC (Remote Procedure Call) framework.
  • GraphQL: Allows clients to specify queries, reducing the number of endpoints needed.

8. Microservices

This architecture involves a collection of small, loosely coupled services, allowing independent updates and scalability.

👉 Tools like Kubernetes (K8s) and Docker are used to manage these services.

9. Message Queues

It facilitates asynchronous communication between services.

Patterns include:

  • Pub/Sub: Publishers send messages to topics, and subscribers receive the messages on subscribed topics.
  • Message Broking: Involves producers, consumers, and brokers.
Kafka Architecture

Why Kafka? Distributed event store and stream-processing platform developed by LinkedIn developers for real-time data streaming and handling high-volume, low-latency data tasks.

10. Database Sharding

Sharding splits a database into smaller, more manageable pieces across servers.

Basic Diagram to visualize Database Sharding
  • Horizontal sharding distributes data based on a key.

Examples: Dividing user data based on user IDs/ Geographical regions.

  • Vertical sharding separates data types, such as user data in one database and transaction data in another.

Examples: Separate financial data, such as account details and transactions.

11. Master-Slave Replication

Setup where, one database server (master) handles writes, while multiple slave servers handle reads.

👉 Slave servers can write under certain conditions but require synchronization with the master.

Typical Web Application Architecture (by ByteByteGo)

👉 For those looking to excel in system design

  • System Design Primer” on GitHub, provides comprehensive insights and practical guidance.
  • ByteByteGo by Alex Yu offers an excellent platform for mastering system design interviews.

📌Mastering these core concepts is key to building scalable, secure, and efficient software systems, boosting both performance and reliability.

--

--