Elasticache Flashcards

1
Q

What are some key differences between Reddis and Memcached?

A

Memcached: Key/Value pairs. Multithreaded. Good for simpler cache use cases.

Reddis: Complex data types and structures. Can be persisted to disk, can sort and rank data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 2 engines used by elasticache

A

Reddis and Memcached

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can a write through cache be stale?

A

No. With a write through cache as data is written to the database, it is also written to the cache - the cache is therefore always current

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Is Elasticache multi-AZ for both Reddis and Memcached?

A

yes to both

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

I need a multithreaded in memory cache - would I use Memcached or Reddis?

A

Memcached is multi threaded

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which cacheing engine supports complex datatypes, ket store persistence and read replicas for read intensive applications?

A

Reddis

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Would we expect reads in an application using write through cache to be faster or slower than those for lazy loading?

A

Faster - as cache is kept up to date

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a DISADVANTAGE of using lazy loading (aka cache aside/lazy population)

A

Data can become stale when using a lazy loading strategy. As lazy loading is read based, if it finds a hit in the cache it will use that - however if the underlying data in the database has changed, this data will be out of date.

Also, there is a read penalty that is incurred with lazy loading.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

For lazy loading, how many round trips occur and to where when there is a cache miss?

A
  1. First round trip is to the cache to return the miss. Second round trip is to the database to select the data. Third round trip is back to the cache to update it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe this code and the caching strategy it reflects:

def get_user(user_id)
 record=cache.get(user_id)
 if record is None:
    record=db.query("select * from users where Id=?", 
                                  user_id )
    cache.set(user_id, record)
    return record
else:
    return record

user=get_user(12)

A

This represents a lazy loading cache strategy. Here, we attempt to retrieve the user_id from the cache. If its a miss (record is None) we execute a select against the db and write the result back to the cache and then return it from the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Does memcached allow for data persistence?

A

No, it is in memory only. If the node goes down the data is lost

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What scaling actions will you need to take if you are seeing a large number of cache evictions due to memory constraints?

A

Its likely you will need to scale up or scale out.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Who is responsible for a cache invalidation strategy?

A

As the developer - you are.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When starting a memcached elasticache cluster, will the cache be empty. What about for reddis?

A

Memcached will always start empty. Reddis can be restored from backup

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which elasticache engine is multi-threaded

A

Memcached

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Both Elasticache and DynamoDB can be used to store session data for a web application, and both use key value pairs. Given this, why would you use one over the other?

A

you would use Elasticache if you specifically needed an in memory datastore.

You would use DynamoDB if you needed a SERVERLESS solution that can scale automatically.

17
Q

Which elasticache engine supports read replicas and which supports sharding?

A

Reddis supports read replicas, Memcached supports sharding

18
Q

Name 2 use cases for elasticache

A

DB offload (for reads), Session management (for stateless applications)

19
Q

What are TWO disadvantages of a write through cache?

A
  1. While data cannot be stale - it can be missing until it is added or updated. This can be mitigated by using write through cache in conjunction with lazy loading
  2. Cache Churn - a lot of data will be written to cache, but it may never be read. This can be a problem if you have a small cache.
20
Q

How many memcached nodes can you have per cluster. How many for Reddis? Which supports replication groups?

A

20 for memcached, 1 for reddis. Reddis clusters can be grouped into replication groups

21
Q

What are the 2 key caching strategies you can use

A

Lazy Loading and Write Through

22
Q

There are 3 ways to evict an item from cache. What are they?

A

Specifically Delete an Item
Eviction due to high memory utilisation
TTL

23
Q

What sort of penalty does lazy loading incur - read or write?

A

Read due the 3 round trips needed

24
Q

Name two ADVANTAGES of lazy loading

A
  1. You only have required data in the cache so it isn’t filled with un-used data. This is because the cache is populated on a MISS
  2. Node failures are not fatal. If a node goes down, there will increased latency as the nodes are “warmed” (i.e. caches are repopulated)
25
Q

Describe this code and the caching strategy it reflects:

def save_user(user_id, values)
 record=db.query("update users ... where id=?", user_id, 
                               values)
 cache.set(user_id, record)
 return record

user=save_user(17, (“name”: “Scott Tiger”))

A

This reflects a write through cacheing strategy. As soon as a record is written to the database, it is also written to the cache

26
Q

You need to implement a caching solution within your application that allows allows for backup and restore. Would you use memcached or reddis?

A

Reddis supports backup and restore

27
Q

If I wanted a caching engine which allowed for pub/sub capability - which would I use, memcached or redis?

A

Redis.

28
Q

Which caching engine allows for horizontal scalability and why?

A

memcached as it is multithreaded and allows for 20 nodes per cluster.

29
Q

I need a caching engine that allows for multi-az operation for fail over. Which would I use?

A

Redis.