logoNEURAL COOK
SearchAll PostsTagsNotesAuthor
instagramtwitterfacebookyoutubelinkedinmailgithubrss
Copyright © 2026 All rights reserved.
•
VIKI
Built with Vikramaditya Singh
Built with
VIKI - A posts created with Next.js and Tailwind.css
About
API Gateway
Batching
Cache
CAP
Consistent Hashing
Counting At Scale
CQRS
CRDT
Database Scaling
Database Selection Strategy
Event Sourcing
Handling Failure
Vertical vs Horizontal Scaling
Id Generation
Indexes
Kafka
Kubernetes
Large Files
Load Balancing
Proxy
Real Time Push
Redis
Scaling Reads
Stateless vs Stateful Systems
Scaling Writes
System Design

Scaling Reads

Different read patterns need fundamentally different solutions.

WorkloadExampleStrong starting point
Point lookupsGet account by IDIndex, cache, read replica
Repeated readsPopular product or configurationLocal/distributed cache
Range queriesRecent orders for a tenantComposite index, keyset pagination
SearchFull-text product searchSearch index
Analytical scansRevenue by region over six monthsColumnar lakehouse, analytical warehouse
AggregationsDaily API usage by tenantMaterialized aggregates or streaming projections
Read-after-writeUpdate profile, immediately retrieve itPrimary or version-aware read
Globally distributed readsUser reads data from nearby regionsRegional replicas/caches with explicit consistency rules
Hot-key workloadOne celebrity profile receives millions of readsReplication, local caching, request coalescing

!!! info "Key Principle" The goals: - Throughput: more requests per second. - Latency: lower response time, especially p95/p99. - Concurrency: more simultaneous in-flight reads. - Freshness: less delay between a write and a visible read.

Scale the layer that is actually saturated, and choose how much staleness your product can tolerate before choosing the read-scaling technique.

# Reduce unnecessary work

Fix query plans, indexes, N+1 queries, excessive payloads, unnecessary joins, and repeated calculations.

# Reuse results safely

Serve repeated requests from a local cache, Redis, or a CDN instead of querying the database every time.

Cache layerBest useMain limitation
CDN / edge cachePublic, reusable responses close to clientsCache-key correctness, freshness, origin protection
Process-local cacheVery hot, compact data needed with minimal latencyPer-instance duplication and invalidation
Distributed cacheShared, dynamic data accessed by many application instancesNetwork latency, cache availability, consistency
Database buffer/page cacheRepeated access to the same database pagesMemory contention with other database work
Analytical disk/data cacheRepeated scans of the same files or datasetsEffectiveness depends on locality and data reuse

Use layered caching when it fits the workload.

# Redis

Caching stores the result of a read so that later requests can reuse it rather than recomputing or reloading it.

# CDN

# Precompute on Write (Materialised View)

When reads are expensive to compute dynamically

# denormalized read models

# Materialized views

Use when a repeatable aggregation or join is costly to recompute.

# CQRS

# Distribute remaining reads

# Read Replicas

A read replica is a secondary database instance that applies changes originating from an authoritative database and serves eligible reads.

Distribute eligible read queries across database replicas rather than sending every read to the primary.

!!! warning "Replication can become the bottleneck" Suppose a write-heavy application produces a high volume of updates to a large number of records. Every replica must keep up with those changes. If the apply rate is lower than the incoming change rate, replication lag grows.

# Read consistency

Consistency requirementPossible implementation
Eventual consistencyAny healthy replica; updates become visible eventually
Bounded stalenessRoute only to replicas within an agreed freshness bound, or use a source that can enforce that bound
Read-your-writesRoute a session to an eligible primary or wait for the replica to reach the client's write version
Monotonic readsTrack the latest version observed by a client and prevent later reads from returning older state
Strong consistencyUse an appropriate authoritative or consensus-backed read mechanism

# Query-serving fleets

A query-serving fleet is a horizontally scaled tier of stateless or semi-stateful servers dedicated entirely to executing read-only user queries with ultra-low latency

# Partition the workload

# Sharding

Partitioning the data can increase aggregate capacity. A shard router maps a key to a partition

!!! "info" For a multi-tenant platform, tenant_id can make tenant-scoped queries efficient, but a very large tenant can become a hot shard. Hashing a record ID may distribute records more evenly, but can make tenant-wide queries expensive.

# Independent read stores

# Observability and SLOs for read systems

SignalWhy it matters
End-to-end p50/p95/p99Captures the user-visible read path
Requests by endpoint and query classIdentifies workload growth and hotspots
Cache hit/miss/error ratioMeasures whether the cache actually reduces source load
Database query latency and throughputShows the source database's real performance
Replica lag / applied versionIndicates whether a replica is eligible for a freshness-sensitive read
Connection-pool wait timeDetects contention before the query reaches the database
CPU, memory, I/O and networkHelps locate resource bottlenecks
Queue depth and rejected workShows saturation and backpressure
Read fallback and stale-serving rateExposes degraded correctness or resilience modes
Cost per successful request/queryHelps evaluate whether a scaling change was worthwhile
PreviousRedisNextStateless vs Stateful Systems
CONTENTS
Reduce unnecessary workReuse results safelyRedisCDNPrecompute on Write (Materialised View)Distribute remaining readsRead ReplicasQuery-serving fleetsPartition the workloadShardingIndependent read storesObservability and SLOs for read systems