Efficiency
Caching layers, Asynchronism, and Communication Protocols.
- Implement appropriate cache invalidation strategies.
- Design background processing systems using message queues.
- Analyze performance differences between REST and gRPC.
- Identify basic security vulnerabilities in architectural designs.
01 Caching Across Multiple Layers Viz
Cache-aside
The application looks in the cache; if not found, it retrieves it from the DB and saves it in the cache.
- **Write-through**: Data is written to the cache and DB simultaneously.
- **Write-behind**: Data is written to the cache first, then to the DB periodically.
- **Refresh-ahead**: The cache automatically updates data before it expires.
Use it for data that rarely changes but is very frequently read (e.g., product details, system configurations).
TTL (Time To Live)
The duration of how long data is allowed to stay in the cache before being considered stale.
02 Asynchronous Processing: Queues & Workers
Use queues to improve user 'Responsiveness'.Deeper InsightUsers hate seeing a spinning loader for too long. Give quick confirmation, process in the background. Click to collapse
- **Message Queue**: RabbitMQ, Redis Pub/Sub.
- **Stream Processing**: Apache Kafka (for very massive data).
- **Back Pressure**: A technique to limit traffic if the queue is too full so the system doesn't crash.
03 Communication Protocols & Security
| Aspect | REST | gRPC (RPC) |
|---|---|---|
| Data Format | JSON (Text) | Protobuf (Binary) |
| Speed | Medium | Very Fast |
| Ease of Use | Very Easy | Requires More Setup |
| Usage | Public API | Internal Microservices |
Comparison of REST and gRPC.
Always sanitize user input and use HTTPS for all data communication paths.
Key Takeaways
- 1Caching is a double-edged sword; very fast but difficult to manage validity.
- 2Use asynchronicity for heavy tasks to keep the UI responsive.
- 3Choose the appropriate communication protocol (REST for external, RPC for internal).
- 4Security must be designed from the start (Security by Design).
CH.04
Chapter Complete
Chapter Progress
Interact with the visualization
System Efficiency Quiz
Test your understanding of caching, message queues, and communication protocols.
Ready to test your knowledge?