Maybe. It depends on how important your cache invalidation is.
If the purpose of your cache is to relieve load from another system (like a database) or improve speed, where you can allow values to be stale and expire naturally with a TTL, a generic load balancer can work acceptably. Suppose you generate an RSS feed of thousands or millions of posts — you can cache this without needing to explicitly invalidate any values, and the natural TTL expiration will work fine. You’ll get more cache misses than if you had a single cache server, but you can spread the load across multiple caches, and if one goes down, you still maintain availability.
However, if you need up-to-the-second accuracy (that is, relatively fast eventual consistency) in your cache, a load balancer in front of the cache server is going to cause some problems, unless you have a sophisticated mechanism for dealing with them.
When you invalidate a cached value, the invalidation will only happen on one server, not all servers. As a result, your application will experience these problems:
- Mixed values in the cache for the same key.
- Stale value in some server(s), resulting in incorrect application logic.
If having up-to-the-second consistency is important for a cached value, maybe it shouldn’t be cached. Or, you need a solution that is more sophisticated than a standard load balancer.