Skip to content
tezvyn:

Design a highly available entitlements service with caching

Source: enterprise-knowledge.comHardHow cards are made

Design a highly available entitlements service with caching

This tests balancing read performance with consistency in access control. A strong answer proposes tiered caching with proactive invalidation, read-optimized hot paths, and event-sourced temporary grants.

What's really being asked

The interviewer wants to see if you understand that entitlements sit on the critical path of every user request, so latency and availability are paramount. They are testing your ability to reason about distributed caching, cache invalidation, handling time-bound state like temporary grants, and maintaining consistency across regions without turning the database into a bottleneck.

The full answer

First, a multi-tier cache strategy. Use a local in-process cache like Caffeine for sub-millisecond hot lookups, backed by a distributed Redis cluster with TTL for cross-instance consistency. Second, a proactive invalidation pipeline. Writes to the entitlement store should publish invalidation events over a message bus so both local and remote caches evict stale entries immediately rather than waiting for TTL. Third, separation of hot and cold paths. Static plan features can be cached aggressively; temporary grants need short TTLs or event-sourced append-only logs so they do not pollute the main cache with churn. Fourth, resilience patterns. Deploy circuit breakers around cache misses to prevent a cold cache from overwhelming the primary database, and use cache warming after deploys. Fifth, consistency model clarity. Acknowledge that entitlements can tolerate brief eventual consistency for reads but require atomic writes, so use write-through caching with optimistic locking on the primary store.

The mistakes people make

Proposing a single shared Redis instance with no invalidation strategy and relying solely on TTL. This creates stale data windows where a user pays for a plan but cannot access features, or worse, retains access after cancellation. Another red flag is ignoring the thundering herd problem; if the cache expires and thousands of requests hit the database simultaneously, the service collapses. Suggesting strong consistency everywhere is also a mistake because it forces cross-region coordination on every read and destroys latency.

What usually comes next

How do you handle a cache invalidation event that gets dropped? How do you model temporary grants without degrading cache hit rates? What happens when the primary database is partitioned but the cache is still serving data, and do you allow or deny access? How do you rollout a new plan definition without restarting the service?

A concrete example

Imagine a streaming platform where users upgrade from Basic to Premium mid-session. The entitlement service receives the plan change, writes to PostgreSQL, and emits an invalidation event to Redis pub-sub and Kafka. Edge nodes consume the event and evict the local Caffeine entry. The next request from that user misses local cache, hits Redis which also misses, then queries PostgreSQL and repopulates both layers. For a temporary grant like a 48-hour sports pass, the system writes an append-only event with an explicit expiration timestamp; the cache stores it with a TTL matching the expiration, so no explicit invalidation is needed when it lapses.

Interview question

In a tiered entitlement cache, how should temporary grants be modeled to avoid degrading cache hit rates?

  • a.Store them in the local in-process cache with the same long TTL as static plan features
  • b.Enforce strong consistency across regions for temporary grants while using eventual consistency for static features
  • c.Query the primary database directly for every temporary grant check to avoid cache churn
  • d.Append them to an event-sourced log and cache with a TTL matching their explicit expirationCorrect
Why?

Temporary grants are high-churn, time-bound state that pollutes the cache if handled like static features; event-sourced append-only logs with precise TTLs keep them off the hot path without overwhelming the database. Querying the primary store directly for every check would recreate the exact bottleneck a multi-tier cache is designed to prevent.

Just read this? Test yourself on what you have been reading.

Read the original → enterprise-knowledge.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles