Cache Tier
A tier stands between the webserver and the database.
If there is data in Javascript cache then return it.
If data doesn't exist in cache then save it into cache.
Caching consideration
- Expiration policy
- Specify TTL for a cache so that the cache can be invalidate itself
- use when data is read frequently but modified infrequently.
- Since it's in-memory, if the cache restarts, everything will gone
- Eviction policy
- When TTL has not expired and there is in coming cache. We need to be able to evict it
- Some of the common algorithms
- Least Recently Used (LRU)
- Least Frequently Used (LFU)
- First in First Out (FIFO)
- Consistency
- Need to make sure that the data in database and the data in cache is in sync. This depends on our write strategy.
- Do we only update when cache hits or when database is updated?
- Especially when caching between multiple region as well
- Mitigating failure
- Single cache server == single point of failure.
- We need multiple cache server across different data centers to avoid failure