Prepare and test your skills

Prepare and test your skills

Free sample question with answers and detailed explanation below. The Professional Cloud Developer practice bank has an additional 608 practice questions.Try 10 free realistic questions: instant score, no credit card, and no account required.
Your team is building an e-commerce service using Cloud SQL and Memorystore for Redis (using the default volatile-lru eviction policy) to cache product pricing and inventory. The application currently checks the cache on reads and queries Cloud SQL on a cache miss.
You must satisfy these requirements:
maxmemory-gb without triggering out-of-memory (OOM) errors as the catalog grows.Which caching strategy and lifecycle configuration should you implement?
Lazy loading (cache-aside) populates the cache reactively: the application reads from Memorystore for Redis first and, only when a cache miss occurs, fetches the record from Cloud SQL and writes it into the cache. The allkeys-lfu eviction policy evicts the least frequently used keys across the entire keyspace—regardless of whether a TTL is set—whenever memory reaches maxmemory-gb.
allkeys-lfu. Consequently, those hot keys are retained in memory indefinitely, continuing to serve outdated pricing or inventory data to users.volatile-lru, allkeys-lfu prevents OOM errors even without TTLs because all keys are eligible for frequency-based eviction.This approach would be suitable for read-heavy, mostly static data (or workloads that explicitly invalidate or update keys on every write) where slight staleness is acceptable and maximizing hit ratios for the hottest keys is the primary goal.
Even when using an allkeys-* policy to avoid OOM conditions, lazy loading requires either TTLs or synchronous write-through updates/invalidations to keep rapidly changing inventory and pricing data accurate.
A write-through caching strategy writes modified data synchronously to both the in-memory cache and the persistent database within the same update flow. Pairing this pattern with Time-to-Live (TTL) settings on keys in Memorystore for Redis enables the default volatile-lru eviction policy to remove the least recently used keys that have an expiration configured whenever memory usage reaches the maxmemory-gb threshold.
volatile-lru policy only evaluates keys that have an active TTL. Assigning TTLs (such as via EXPIRE or SETEX) ensures Redis always has eligible keys to evict as maxmemory-gb fills up, preventing -OOM command not allowed under OOM prevention errors while also bounding how long inactive entries occupy memory.volatile-lru proactively evicts cold expiring keys under memory pressure.Unlike write-back caching, write-through guarantees immediate consistency between Memorystore for Redis and Cloud SQL. Unlike lazy loading without writes, it prevents stale cache entries after updates. Finally, configuring TTLs makes the default volatile-lru policy functional, avoiding the memory exhaustion that occurs when keys lack expiration metadata.
The write-back (write-behind) strategy writes new or updated data to the in-memory cache first and persists those changes to the backing database asynchronously at a later time. The noeviction maxmemory policy instructs Memorystore for Redis to never evict keys when memory reaches maxmemory-gb, instead rejecting new write commands with an error.
noeviction directly violates the memory safety requirement. As the product catalog grows and maxmemory-gb fills, Redis refuses to evict older entries and immediately returns out-of-memory errors (-OOM command not allowed under OOM prevention), breaking application writes.noeviction requires provisioning enough memory to hold the entire peak working set plus overhead, because Redis will not free space automatically.maxmemory-gb is reached under noeviction, commands such as SET fail while read operations continue.This configuration would only be appropriate for a write-heavy workload where Cloud SQL can tolerate delayed, asynchronous updates, AND the cache is sized well above the peak dataset size so noeviction is intentionally used to treat Redis as an un-evictable store.
Developers often choose noeviction hoping to protect unpersisted write-back data from premature eviction. However, relying on an in-memory cache without TTL or eviction headroom turns normal catalog growth into a service outage.
A write-through caching strategy synchronously updates both Memorystore for Redis and Cloud SQL on every write. In Redis, the default volatile-lru eviction policy attempts to reclaim space at maxmemory-gb by removing the least recently used keys only from the subset of keys that have an expiration (TTL) set.
volatile-lru with zero eligible keys to evict when maxmemory-gb is reached. Because Redis cannot evict non-expiring keys under any volatile-* policy, memory fills completely and new writes fail with out-of-memory (OOM) errors.volatile-* policy (such as volatile-lru or volatile-lfu) strictly ignores keys that do not have an explicit expiration time.volatile-lru finds no keys with a TTL to remove, it behaves identically to noeviction and rejects write commands.Leaving keys without TTLs would work only if you changed the maxmemory policy to an allkeys-* policy (such as allkeys-lru or allkeys-lfu), which evicts any key regardless of whether a TTL is attached.
A common misconception is that volatile-lru evicts any least recently used key once memory is full. In reality, volatile specifically refers to keys marked with an expiration time; without TTLs, volatile-lru cannot protect an instance from running out of memory.
Answer them yourself and get your score the moment you finish. No account needed.
Full access includes
Keep the momentum going with these hand-picked practice scenarios
Last updated Validated