Roadmap › Microservices & System Design with .NET › Module: Running Microservices in Production
Lessons in this course (9)
9. Scaling, caching and the system design round
Advanced★ Must knowLesson 9 of 9
Scaling:
- Vertical — bigger machine (simple, limited). Horizontal — more instances behind a load balancer; services must be stateless (session in Redis/cookies, files in Blob storage).
- Database scaling — indexes first, then read replicas, caching, partitioning, and finally sharding.
- Autoscaling — Kubernetes HPA / KEDA (scale on queue length), App Service autoscale, Container Apps scale rules.
Caching strategies:
| Strategy | How |
|---|---|
| Cache-aside | App reads cache → on miss reads DB and fills cache (most common) |
| Write-through | Write to cache and DB together |
| Expiry + invalidation | TTL, plus delete keys on update; beware stale data and stampedes |
| Where | Browser/CDN → API output cache → distributed cache (Redis) → DB buffer pool |
csharp
// .NET 9+ HybridCache: in-memory + distributed, with stampede protection
var product = await cache.GetOrCreateAsync($"product:{id}",
async ct => await db.Products.FindAsync([id], ct), new HybridCacheEntryOptions { Expiration = TimeSpan.FromMinutes(10) });System design answer template: requirements (functional + non-functional) → estimates (users, RPS, storage) → API → data model → high-level diagram → deep dive on 1–2 hard parts → bottlenecks, failures and trade-offs.
Classic designs to practise: URL shortener (key generation, redirects, cache, analytics), e-commerce checkout (saga, stock, payment idempotency), notification service (queues, retries, templates, preferences), rate limiter (token bucket in Redis), chat (WebSockets/SignalR, fan-out, presence), file upload service (pre-signed URLs, Blob storage, virus scan queue).