Skip to content
ML SystemPart 4: EfficiencyChapter 4
Efficiency CH.04 ~25 min

Efficiency

Caching layers, Asynchronism, and Communication Protocols.

cachingasynchronismmessage queuesRESTgRPC
  • 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

Definition

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.
When to Use a Cache?

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

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

Comparison of REST and gRPC.
AspectRESTgRPC (RPC)
Data FormatJSON (Text)Protobuf (Binary)
SpeedMediumVery Fast
Ease of UseVery EasyRequires More Setup
UsagePublic APIInternal Microservices

Comparison of REST and gRPC.

Basic Security

Always sanitize user input and use HTTPS for all data communication paths.

Key Takeaways

  1. 1Caching is a double-edged sword; very fast but difficult to manage validity.
  2. 2Use asynchronicity for heavy tasks to keep the UI responsive.
  3. 3Choose the appropriate communication protocol (REST for external, RPC for internal).
  4. 4Security must be designed from the start (Security by Design).

CH.04

Chapter Complete

Up next:Case Studies

Chapter Progress

Reading
Exercise

Interact with the visualization

Quiz

System Efficiency Quiz

Test your understanding of caching, message queues, and communication protocols.

Ready to test your knowledge?

5 questionsRandomized from pool70% to pass