Showing 30 question(s)
Answer:
System Design is the process of designing scalable, reliable, maintainable, and efficient software systems that meet functional and non-functional requirements.
Code Example:
Client
|
Load Balancer
|
Application Servers
|
DatabaseAnswer:
Functional requirements describe what a system should do, while non-functional requirements define performance, scalability, reliability, security, and availability expectations.
Code Example:
Functional:
- User Login
- Search Products
Non-Functional:
- 99.9% Availability
- <200ms Response TimeAnswer:
Scalability is the ability of a system to handle increasing traffic or workload by adding more resources.
Code Example:
Vertical Scaling
Server ↑ CPU ↑ RAM
Horizontal Scaling
Server1
Server2
Server3Answer:
High Availability ensures a system remains operational even when hardware or software failures occur.
Code Example:
Load Balancer
/ \
App1 App2Answer:
Fault Tolerance allows a system to continue functioning despite failures in one or more components.
Code Example:
Primary DB
|
Replication
|
Replica DBAnswer:
Client-Server Architecture separates the client that requests services from the server that processes requests and returns responses.
Code Example:
Client ---> ServerAnswer:
A monolithic application contains all business logic, UI, and database access in a single deployable unit.
Code Example:
Application
├── UI
├── Business Logic
└── DatabaseAnswer:
Microservices divide an application into independent services that communicate through APIs or messaging.
Code Example:
API Gateway
| | |
User Product OrderAnswer:
An API Gateway acts as a single entry point for clients and routes requests to appropriate backend services.
Code Example:
Client
|
API Gateway
| | |
User Product PaymentAnswer:
Service Discovery enables services to locate and communicate with each other dynamically without hardcoded addresses.
Code Example:
Service A
|
Service Registry
|
Service BAnswer:
Horizontal scaling means adding more servers or instances to distribute traffic and improve system capacity.
Code Example:
Users
|
Load Balancer
/ | \
S1 S2 S3Answer:
Vertical scaling increases CPU, RAM, or storage of an existing server instead of adding new servers.
Code Example:
Server
CPU: 4 -> 16
RAM: 8GB -> 64GBAnswer:
Caching stores frequently accessed data in memory to reduce database queries and improve response time.
Code Example:
Client
|
Cache (Redis)
|
DatabaseAnswer:
Common cache eviction policies include LRU (Least Recently Used), LFU (Least Frequently Used), FIFO, and TTL-based expiration.
Code Example:
LRU
LFU
FIFO
TTLAnswer:
Database sharding splits data across multiple databases based on a shard key to improve scalability.
Code Example:
Users A-M -> DB1
Users N-Z -> DB2Answer:
Replication copies data from a primary database to one or more replicas for high availability and read scalability.
Code Example:
Primary DB
|
---------
| |
Replica ReplicaAnswer:
A load balancer distributes incoming requests across multiple servers to improve availability and performance.
Code Example:
Users
|
LB
/|\
S1 S2 S3Answer:
Layer 4 load balancers route traffic based on TCP/UDP information, while Layer 7 load balancers route using HTTP request details like URL or headers.
Code Example:
L4 -> TCP/UDP
L7 -> HTTP/HTTPSAnswer:
A message queue enables asynchronous communication between services by storing messages until they are processed.
Code Example:
Producer
|
Queue
|
ConsumerAnswer:
Event-driven architecture allows services to communicate through events instead of direct synchronous requests.
Code Example:
Service A
|
Event Bus
/ | \
B C DAnswer:
CAP theorem states that a distributed system can guarantee only two out of Consistency, Availability, and Partition Tolerance at the same time.
Code Example:
CAP
C = Consistency
A = Availability
P = Partition ToleranceAnswer:
Eventual consistency means all replicas will eventually contain the same data if no new updates occur.
Code Example:
Write
|
Primary
|
Replicas
(Eventually Sync)Answer:
Fault tolerance enables a system to continue operating correctly even when one or more components fail.
Code Example:
Server1 ❌
Server2 ✅
Server3 ✅Answer:
High availability ensures systems remain operational with minimal downtime using redundancy and failover mechanisms.
Code Example:
Load Balancer
/ \
Server1 Server2Answer:
A Content Delivery Network (CDN) caches static content on geographically distributed edge servers to reduce latency.
Code Example:
User
|
Nearest CDN
|
Origin ServerAnswer:
DNS translates domain names into IP addresses so users can access services using human-readable names.
Code Example:
example.com
|
DNS
|
192.168.x.xAnswer:
Monitoring helps track application health, performance, resource utilization, failures, and alerts in production systems.
Code Example:
Application
|
Prometheus
|
GrafanaAnswer:
Distributed tracing follows requests across multiple services to identify latency and failures.
Code Example:
Client
|
API
|
Service A
|
Service BAnswer:
CQRS separates read and write operations into different models, improving scalability and performance.
Code Example:
Write Model
|
Database
|
Read ModelAnswer:
Use stateless services, load balancing, caching, asynchronous messaging, database indexing, replication, monitoring, autoscaling, fault tolerance, and secure communication to build scalable and reliable distributed systems.
Code Example:
Users
|
Load Balancer
|
App Servers
|
Cache
|
Database