How ElastiCache for Redis works...

Hello all.

I am having trouble understanding the concept of in-memory cache.

The definition says services like redis saves cache in RAM, so it improves the performance.

  1. but RAM is about 16GB, 32GB, do you mean cache takes up those little capacity?
  2. if you use redis in AWS, redis server is not inside EC2, but it’s a standalone redis server. How does it make difference with using RDS, if the in-memory is not attached to EC2?

Thank you.

  1. Yes - you will typically have less available storage than with a traditional database. You’ll typically have 75% of the instances available memory available for your cache (as a certain % is needed to handle failover & backups without running out of memory).

  2. Both RDS and Elasticache abstract the instance away from you. Perhaps it is running on an EC2 instance behind the scenes - but that isn’t relevant to you. You just need the endpoint in order to interact with the database or cache.

Here’s a typical process.

A user logs into your service. Your system will check the database to see if it’s a valid user. Yes he is. Ok return the user details to be displayed on the Profile page.

The user navigates to a different page. Then goes back to the Profile page. Your backend will need to query the database again to load the user details.

Now, instead of the second database call, you could have saved the user details in Redis. So the subsequent visits will read from a cached copy.

A read from a database is in the millisecond range. A read from Redis is in the nanosecond range. Plus it offsets load from your DB.

The difference with an in-memory cache vs a more traditional database is that redis holds the entirety of its contents in RAM - ensuring very fast access, even counting network calls ie when using elasticache. A traditional database typically only stores indexes in memory, ensuring that you can look up whatever is indexed very quickly - but that only speeds up finding where your data is located on disk, negating the need to to a table scan to find the right data. The data itself is still read from disk, which is way slower than RAM.