Lesson 3 of 8 Performance and Purpose-Built Data Stores

Scaling Reads with Replicas and Local Reads

This lesson explains how read replicas add read capacity without changing the primary and bring data close to distant users, at the price of replication lag that the application must tolerate.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose a replica option.
  • Route reads to replicas with endpoints.
  • Distinguish replicas from caches and disaster recovery copies.

Replica options

Read-heavy workloads scale by spreading reads across copies of the data. Aurora supports up to 15 replicas that share the cluster's storage, so replication lag is typically under 100 ms. A reader endpoint balances connections across them, and Aurora Auto Scaling adds and removes replicas with the load. RDS for MySQL, MariaDB, PostgreSQL, Oracle and SQL Server supports up to 15 asynchronous read replicas, in the same Region or another. Aurora Global Database adds up to ten secondary Regions with sub-second lag, so users read locally.

DynamoDB eventually consistent reads cost half as much as strongly consistent ones, and global tables give local reads and writes in other Regions. ElastiCache adds replicas within each shard, and Global Datastore extends it to other Regions. The following table summarises the options.

Data storeRead scaling
AuroraUp to 15 replicas sharing the cluster storage, typically under 100 ms lag, behind a reader endpoint; Aurora Auto Scaling adds and removes replicas
RDS (MySQL, MariaDB, PostgreSQL, Oracle, SQL Server)Up to 15 asynchronous read replicas, in-Region or cross-Region
Aurora Global DatabaseUp to 10 secondary Regions with sub-second lag for local reads
DynamoDBEventually consistent reads at half the cost; global tables for local reads and writes in other Regions
ElastiCacheReplicas within a shard; Global Datastore for other Regions

Routing reads

Replicas add capacity only if reads are sent to them. Applications send writes to the writer or cluster endpoint and reads to the reader endpoint, which balances connections across replicas; frameworks and drivers, such as the AWS Advanced JDBC Wrapper, can split reads and writes automatically. Aurora custom endpoints group particular replicas for particular workloads, for example larger replicas for reporting, so heavy analytical queries do not slow the application's reads.

Replication lag means a replica may not yet have the latest write. Reads that must see a write the user has just made, such as displaying a profile immediately after saving it, therefore go to the writer, while reads that tolerate a short delay go to replicas.

Replicas are not a cache, and not always DR

Read replicas are often confused with caches and with disaster recovery copies. A cache returns precomputed results in microseconds and suits repeated reads of the same data; a replica executes queries and adds capacity for queries that cannot be cached, such as searches with many different parameters. Replicas reduce read load but not write load, so write scaling needs sharding, Aurora Limitless Database or a different data store.

Cross-Region replicas can be promoted for disaster recovery, but promotion is a manual or scripted action, and writes not yet replicated, equal to the lag at the moment of failure, are lost. A design that needs managed cross-Region failover uses Aurora Global Database or DynamoDB global tables instead.

Worked example

Elastic read capacity with a separate reporting endpoint

An Aurora MySQL cluster serves an application whose read traffic doubles at month-end, and a finance team runs heavy reports that slow the application when they share replicas. The architect adds Aurora Auto Scaling for the application's replicas and a custom endpoint for reporting:

aws application-autoscaling register-scalable-target --service-namespace rds \
  --resource-id cluster:orders --scalable-dimension rds:cluster:ReadReplicaCount \
  --min-capacity 2 --max-capacity 8
aws application-autoscaling put-scaling-policy --policy-name reader-cpu --service-namespace rds \
  --resource-id cluster:orders --scalable-dimension rds:cluster:ReadReplicaCount \
  --policy-type TargetTrackingScaling --target-tracking-scaling-policy-configuration \
  '{"TargetValue":60.0,"PredefinedMetricSpecification":{"PredefinedMetricType":"RDSReaderAverageCPUUtilization"}}'

aws rds create-db-cluster-endpoint --db-cluster-identifier orders --db-cluster-endpoint-identifier reporting \
  --endpoint-type READER --static-members orders-reporting-1

The application uses the cluster's reader endpoint, which spreads connections across the auto-scaled replicas; the reporting tool connects to the reporting endpoint, whose single, larger replica is excluded from the application's pool. Reads that must reflect a write the user has just made, such as the order confirmation page, are sent to the writer endpoint, because replicas can lag by tens of milliseconds.

Check yourself

Why is a read replica not automatically a disaster recovery solution?

Show answer

Replication is asynchronous, so recent writes can be lost, and promotion must be done or automated. For DR the replica also needs to be in another Region and the failover tested.

Exam Tips

Remember for the exam

  • To scale Aurora reads elastically, use Aurora Auto Scaling replicas behind the reader endpoint.
  • Use Aurora custom endpoints to isolate reporting queries on dedicated replicas.
  • For low-latency reads in distant Regions, use Aurora Global Database or DynamoDB global tables.
  • Read replicas do not scale writes.
  • Send reads that must be current to the writer, because replicas lag.