Requirements are the foundation of good system design.
VAGUE PROBLEM
|
v
CLARIFY REQUIREMENTS
|
+----+----+
| |
v v
FUNCTIONAL NON-FUNCTIONAL
"WHAT?" "HOW WELL?"
| |
+------+-------+
|
v
CAPACITY ESTIMATE
|
v
CONSTRAINTS
|
v
TRADE-OFFS
|
v
ARCHITECTUREKey idea: Requirements → Constraints → Trade-offs → Architecture.
USER | +--> Send Message | +--> Receive Message | +--> Create Group | +--> View History | +--> Get Notification
Functional requirements describe the actual behavior and features of the system.
SYSTEM / | \ / | \ v v v Customer Admin External System
Actors may include customers, administrators, internal teams, external systems, and other services.
Don't just list features. Understand the workflow.
User | v Select Product | v Validate | v Create Order | v Payment | v External System | v Update Status | v Notify User
Do not try to design the entire product.
REQUIREMENTS
|
+--> MUST HAVE
|
+--> NICE TO HAVE
|
+--> OUT OF SCOPEMust: Send, Receive, History
Nice: Typing indicator, Read receipt, Reactions
Out: Video calling, Voice calling
Once functionality is clear, express it through APIs.
Functional Requirement
|
v
APIPOST /messages
GET /users/{id}/messages
POST /conversations
GET /conversations/{id}/messagesNFRs describe system qualities and constraints rather than features.
Avoid vague statements.
"System should be fast" "System should scale" "Highly available"
Instead:
Users = 10M Messages = 100M/day Latency = p95 < 200ms Availability = 99.99% RPO = 0
Users | +--> 1M → 10M → 100M Traffic | +--> 1K → 10K → 100K RPS Data | +--> GB → TB → PB Geography | +--> India → Asia → Global
Load Balancer
/ | \
v v v
Server Server ServerHorizontal scaling means adding more instances rather than continuously making one server bigger.
Example: 10 million messages/day.
10,000,000 ----------- 86,400 ≈ 116 messages/sec
Then estimate peak traffic.
Average = 116/sec Peak = Average × Peak Factor If peak factor = 10 Peak ≈ 1,160/sec
Then ask: servers, DB writes, queue partitions, storage, bandwidth.
Performance is not just average latency.
p50 < 50ms p95 < 200ms p99 < 500ms
99 users → 20ms 1 user → 10 seconds Average can hide the problem. p99 exposes it.
| Availability | Approx. Downtime / Year |
|---|---|
| 99% | 3.65 days |
| 99.9% | 8.76 hours |
| 99.99% | 52.6 minutes |
| 99.999% | 5.26 minutes |
High Availability
|
+--> Replication
+--> Redundancy
+--> Failover
+--> Multi-AZ
+--> Health ChecksAVAILABILITY
|
v
"Can I access the system?"RELIABILITY
|
v
"Does the system do the correct thing?"Payment API → HTTP 200
|
v
Transaction NOT persisted
|
v
Available = YES
Reliable = NOWRITE | v DURABLE STORAGE | +--> Replication +--> Backup +--> Persistence +--> Recovery
Recovery Point Objective: Maximum acceptable data loss.
RPO = 5 minutes → Potentially lose up to 5 minutes of data
For financial transactions, the target may be close to zero data loss.
Recovery Time Objective: How quickly must the system recover?
System Failure
|
v
10 min
|
v
System Restored
RTO = 10 min Database
/ \
v v
Replica 1 Replica 2
| |
+----?-----+
|
ConsistencyWRITE | v Reads see latest committed value
WRITE
|
+--> Replica A updated
|
+--> Replica B updates later
|
v
Eventually consistent STRONG CONSISTENCY
|
v
More coordination
|
v
Potential latency
|
v
Availability trade-offAssume everything can fail.
Server → FAIL Database → FAIL Network → FAIL Kafka → FAIL Dependency → TIMEOUT Deployment → FAIL Region → FAIL
Failure | +--> Timeout +--> Retry +--> Circuit Breaker +--> Failover +--> Idempotency +--> Dead Letter Queue
Especially important for payment systems.
Client | | Payment ₹1000 v Server | X Timeout
The client may retry, potentially charging twice.
Request
|
+--> Idempotency-Key: ABC123
|
v
Process ONCEMaintainability
|
+--> Modularity
+--> Testing
+--> Documentation
+--> Automation
+--> Clean APIs
+--> Observability
+--> CI/CDSECURITY
|
+--> Authentication
| "Who are you?"
|
+--> Authorization
| "What can you do?"
|
+--> Encryption
| "Can others read it?"
|
+--> Audit
| "Who did what?"
|
+--> Abuse Protection
"Can someone misuse it?"Data in Transit → TLS Data at Rest → Encryption Sensitive Data → Masking / Tokenization APIs → Auth + Rate Limiting
OBSERVABILITY
|
+-----------+-----------+
| | |
Logs Metrics Traces
| | |
What? How much? Where?RPS Error Rate Latency CPU Memory DB Connections Queue Depth
API | | 20ms v Order Service | | 30ms v Payment Service | | 200ms v Bank
Tracing identifies where a request spends its time.
Architecture is also economics.
BUSINESS
|
v
Required SLA / SLO
|
v
Architecture
|
v
COST| Requirement | Architectural Consequence |
|---|---|
| High Traffic | Horizontal Scaling |
| High Availability | Replication + Redundancy |
| Low Latency | Cache + Efficient Communication |
| High Writes | Partitioning / Sharding |
| Heavy Reads | Cache + Read Replicas |
| Strong Consistency | Transactions / Coordination |
| Eventual Consistency OK | Async / Event Driven |
| Zero Data Loss | Durable Storage + Replication |
| Global Users | Multi-Region |
| Security | Auth + Encryption + IAM + Audit |
| Easy Operations | Automation + Observability |
| Low Cost | Right-size Infrastructure |
When choosing a technology, think in this order:
Requirement
|
v
Constraint
|
v
Trade-off
|
v
Pattern
|
v
TechnologyNeed:
High write throughput
|
v
Constraint:
Single DB cannot handle writes
|
v
Trade-off:
Partition data
|
v
Pattern:
Sharding / Partitioning
|
v
Technology:
Choose appropriate DB / QueueWHAT? | Functional | v HOW WELL? | Non-Functional | v HOW MUCH? | Capacity | v WHAT IF? | Failure | v WHAT TRADE-OFF? | v ARCHITECTURE
Requirements → Constraints → Trade-offs → Architecture