Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS ElastiCache vs RDS ReadReplica

My app currently connects to a RDS Multi-AZ database. I also have a Single-AZ Read Replica used to serve my analytics portal.

Recently there have been an increasing load on my master database, and I am thinking of how to resolve this situation without having to scale up my database again. The two ways I have in mind are

  1. Move all the read queries from my app to the read-replica, and just scale up the read-replica, if necessary.
  2. Implement ElastiCache Memcached.

To me these two options seem to achieve the same outcome for me - which is to reduce load on my master database, but I am thinking I may have understood some fundamentals wrongly because Google doesnt seem to return any results on a comparison between them.

like image 494
chongzixin Avatar asked Jul 14 '14 02:07

chongzixin


1 Answers

In terms of load, they have the same goal, but they differ in other areas:

Up-to-dateness of data:

  • A read replica will continuously sync from the master. So your results will probably lag 0 - 3s (depending on the load) behind the master.
  • A cache takes the query result at a specific point in time and stores it for a certain amount of time. The longer your queries are being cached, the more lag you'll have; but your master database will experience less load. It's a trade-off you'll need to choose wisely depending on your application.

Performance / query features:

  • A cache can only return results for queries it has already seen. So if you run the same queries over and over again, it's a good match. Note that queries must not contain changing parts like NOW(), but must be equal in terms of the actual data to be fetched.
  • If you have many different, frequently changing, or dynamic (NOW(),...) queries, a read replica will be a better match.
  • ElastiCache should be much faster, since it's returning values directly from RAM. However, this also limits the number of results you can store.

So you'll first need to evaluate how outdated your data can be and how cacheable your queries are. If you're using ElastiCache, you might be able to cache more than queries — like caching whole sections of a website instead of the underlying queries only, which should improve the overall load of your application.

PS: Have you tuned your indexes? If your main problems are writes that won't help. But if you are fighting reads, indexes are the #1 thing to check and they do make a huge difference.

like image 174
xeraa Avatar answered Nov 16 '22 01:11

xeraa