Keep your caching simple and inexpensive

Caching is a complex topic. It can make your application perform faster, and it can also make your life living hell. Here are some things I learned from experience:

  • If you want to cache data that might be frequently updated and you always need up to date values, you cannot do better than DB cache;
  • Cache coherence is tough to get right. If you have some shared data that you want cached, use a shared cache like Redis or rely on DB;
  • In a distributed stateless system (i.e. AWS Lambda), in-memory caching is ineffective because your compute resources are short-lived. Use a shared cache;
  • In a distributed system, the latency of calls to a shared cache like Redis is outweighed by reliability and consistency. See point 2 on “Cache Coherence.”
  • Memoization helps only when the same expensive function is used many times in the same computation;
  • Always err on the side of open source tools over proprietary. It is highly unlikely that proprietary tools are better;
  • Don’t overthink vendors. Caching is complex but not complex enough to require a complex proprietary product and a vendor contract;
  • If you can’t provision a shared cache service on AWS using the AWS Dashboard, avoid it like a plague. See point above;

Point is — keep your caching simple, inexpensive, and don’t overthink it.