DP-900Chapter 88 of 101Objective 2.5

Azure Cache for Redis for Low-Latency Data

This chapter covers Azure Cache for Redis, a fully managed in-memory data store that provides ultra-low-latency access to data for Azure applications. For the DP-900 exam, understanding how Redis caching reduces latency and database load is critical, as approximately 10-15% of questions touch on caching concepts, including cache-aside pattern, eviction policies, and data persistence. By the end of this chapter, you will be able to explain when and why to use Azure Cache for Redis, how it interacts with Azure SQL Database and Cosmos DB, and how to configure basic caching scenarios. This knowledge is essential for designing high-performance data solutions on Azure.

25 min read
Intermediate
Updated May 31, 2026

Warehouse Inventory vs. Front-Display Shelf

Imagine a busy retail store. The main warehouse (Azure SQL Database) stores all products on deep shelves with a complex retrieval system. When a customer asks for a popular item, fetching it from the warehouse takes minutes—the clerk must walk to the back, locate the shelf, and bring it forward. To speed things up, the store places a small, locked display shelf right at the checkout counter (Azure Cache for Redis). This shelf holds only the top 20 most-requested items. When a customer asks for an item, the clerk first checks the display shelf. If it's there (cache hit), the clerk grabs it immediately—response in seconds. If not (cache miss), the clerk runs to the warehouse, retrieves the item, and also places one copy on the display shelf for future customers. The display shelf has limited space (memory), so when it's full, the clerk must remove the least popular item (eviction policy, e.g., LRU) to make room for a new one. The shelf also has a timer: every 30 minutes, the clerk checks if any item has expired (time-to-live, TTL) and removes it to avoid selling stale goods. This mechanism directly mirrors how Redis caches data: it provides sub-millisecond access to frequently used data, reducing load on the backend database and improving application response times.

How It Actually Works

What is Azure Cache for Redis?

Azure Cache for Redis is a fully managed, in-memory data store based on the open-source Redis (REmote DIctionary Server) engine. It provides extremely low latency (typically <1 millisecond) for data access by storing data in RAM rather than on disk. It is commonly used as a cache layer between applications and backend databases (like Azure SQL Database or Cosmos DB) to reduce latency and database load, but it can also serve as a session store, message broker, or real-time analytics engine.

Why Use a Cache?

Databases store data on disk or SSD, which has access times measured in milliseconds (5-10 ms for SSD, 50-100 ms for HDD). Even with indexing, reading from disk involves physical I/O and is slower than reading from RAM. A cache like Redis keeps frequently accessed data in memory, reducing read latency to microseconds. This is critical for applications that require fast response times, such as e-commerce product catalogs, gaming leaderboards, or real-time dashboards. Additionally, caching reduces the load on the backend database, allowing it to handle more concurrent users or reducing the need for expensive scaling.

How Azure Cache for Redis Works Internally

Azure Cache for Redis stores data as key-value pairs. The key is a unique string identifier, and the value can be a string, list, set, sorted set, hash, bitmap, or other Redis data structures. When an application requests data, it first checks the cache. If the data is present (cache hit), Redis returns it instantly. If not (cache miss), the application retrieves the data from the database, then stores a copy in the cache for future requests. This pattern is called the cache-aside pattern, and it is the most common caching strategy.

#### Cache-Aside Pattern (Lazy Loading)

1.

Application requests data by key.

2.

Redis checks if the key exists.

3.

If yes (cache hit), Redis returns the value immediately.

4.

If no (cache miss), application queries the database.

5.

Application stores the data in Redis with a time-to-live (TTL) value.

6.

Application returns the data to the client.

This pattern ensures that only frequently accessed data is cached, and stale data is automatically removed after the TTL expires.

Key Components and Defaults

- Tiers: Azure Cache for Redis offers three tiers: - Basic: Single node, no SLA, suitable for dev/test. - Standard: Two nodes (primary/replica), 99.9% SLA. - Premium: Two nodes plus additional features like data persistence, clustering, and VNet injection. - Memory Sizes: From 250 MB (Basic C0) up to 120 GB (Premium P5). - Eviction Policies: When memory is full, Redis evicts keys based on the configured policy. Default is volatile-lru (evict keys with TTL set using LRU). Other policies include allkeys-lru, volatile-ttl, volatile-random, allkeys-random, noeviction (returns errors on write). - Time-to-Live (TTL): Optional expiration time set on each key. After TTL expires, the key is automatically deleted. Default is no expiration. - Persistence: Premium tier offers RDB (snapshot) and AOF (append-only file) persistence to disk for durability. - Clustering: Premium tier supports clustering to distribute data across up to 10 shards, allowing caches larger than 120 GB. - Geo-replication: Premium tier supports geo-replication for cross-region disaster recovery.

Configuration and Verification

In the Azure portal, you can create a new Redis cache by specifying:

DNS name (e.g., mycache.redis.cache.windows.net)

Tier and size

Non-SSL port (6379) or SSL port (6380) – recommended to use SSL.

Access keys (primary and secondary)

To connect from an application, you need the hostname and access key. Example connection string for StackExchange.Redis client (C#):

mycache.redis.cache.windows.net:6380,password=yourkey,ssl=True,abortConnect=False

To verify connectivity, you can use the Redis CLI (if installed) or the built-in Console in the Azure portal:

redis-cli -h mycache.redis.cache.windows.net -p 6380 -a yourkey --tls

Then run commands like:

PING
SET mykey "Hello"
GET mykey
TTL mykey

Interaction with Related Technologies

Azure SQL Database: Cache query results (e.g., product catalog) to reduce read load. Implement cache-aside pattern in application code.

Azure Cosmos DB: Cache frequently accessed documents or query results. Cosmos DB also has its own integrated cache (dedicated gateway) but Redis offers more flexibility.

Azure App Service: Use Redis as a session state provider for web apps, storing session data in memory for fast access across multiple instances.

Azure Functions: Cache expensive computations or API responses.

Performance Considerations

Redis is single-threaded for command execution, so latency is very low but throughput can be limited by CPU. Use pipelining or clustering for high throughput.

Network latency between application and cache affects performance. Deploy cache in the same region as the application.

Avoid storing large values (>1 MB) as they cause network and memory overhead.

Monitor cache metrics: Cache Hits, Cache Misses, Evicted Keys, Used Memory, Server Load.

Advanced Features

Redis Transactions: Use MULTI/EXEC to execute a group of commands atomically.

Pub/Sub: Messaging pattern for real-time notifications.

Lua Scripting: Run custom scripts on the server to reduce network round trips.

Redis Modules: Premium tier supports modules like RediSearch, RedisBloom, RedisTimeSeries.

Exam-Relevant Details

The default eviction policy for Azure Cache for Redis is volatile-lru.

The maximum number of databases per Redis instance is 16 (default 0).

Redis supports five basic data structures: strings, lists, sets, sorted sets, and hashes.

Azure Cache for Redis requires a firewall rule to allow client access (by default, only Azure services can access).

The cache-aside pattern is the most common caching pattern tested on DP-900.

Redis persistence is only available in the Premium tier.

Geo-replication is only available in the Premium tier.

The SLA for Standard tier is 99.9%.

SSL port is 6380, non-SSL is 6379.

Common Commands

SET key value [EX seconds] [PX milliseconds] [NX|XX]
GET key
DEL key
EXPIRE key seconds
TTL key
KEYS pattern (avoid in production)

Summary

Azure Cache for Redis is a powerful tool for reducing latency and database load. It stores data in memory, uses key-value pairs, supports various data structures, and offers configurable eviction policies and TTL. The cache-aside pattern is the primary integration pattern. For DP-900, focus on understanding when to use caching, the cache-aside pattern, and the default eviction policy.

Walk-Through

1

Application requests data by key

The application initiates a read operation by calling the cache client library (e.g., StackExchange.Redis) with a specific key. The client serializes the request and sends it over TCP (SSL port 6380) to the Redis server. The server receives the command, parses it, and checks its in-memory hash table for the key. If found, it retrieves the value from the corresponding memory location. This entire lookup takes microseconds (typically <1 ms). The server then serializes the response and sends it back to the client.

2

Cache hit: return data directly

If the key exists in Redis and has not expired, Redis returns the value to the application immediately. The application deserializes the response and uses the data. No database query is made, saving significant latency (from 5-50 ms to <1 ms). This reduces load on the backend database, allowing it to handle more concurrent users. The cache hit ratio is a key performance metric; a high ratio indicates effective caching.

3

Cache miss: query the database

If the key does not exist (or has expired), Redis returns a nil response. The application then queries the primary database (e.g., Azure SQL Database) using its own connection string. The database executes the query, which may involve disk I/O, index scans, and data retrieval. This typically takes 5-50 ms depending on the query complexity and database load. The application receives the result set from the database.

4

Store retrieved data in cache with TTL

After retrieving the data from the database, the application stores it in Redis using a SET command, often with an expiration time (TTL) to avoid stale data. For example: `SET product:12345 "{...}" EX 300` sets the key to expire after 300 seconds (5 minutes). The TTL value should be chosen based on how frequently the data changes. If the data is static, a longer TTL (e.g., 24 hours) is acceptable; if dynamic, a shorter TTL (e.g., 60 seconds) ensures freshness.

5

Return data to the client

Finally, the application returns the data to the original client (e.g., web browser, mobile app). The client experiences the latency of the cache hit (if hit) or the sum of cache miss + database query + cache write. Over time, frequently accessed data becomes cached, improving average response times. The application should also handle cache failures gracefully—if Redis is unavailable, it should fall back to the database directly.

What This Looks Like on the Job

E-Commerce Product Catalog

A major online retailer uses Azure Cache for Redis to cache product details (name, price, description, images) for their top 10,000 products. The backend is Azure SQL Database with millions of products. Without caching, each product page load triggers a database query, causing 50-100 ms latency and high DTU consumption. By implementing cache-aside with a 10-minute TTL, the application achieves <5 ms latency for cached products, serving 90% of requests from cache. The database load drops by 80%, allowing the retailer to handle Black Friday traffic without scaling up. The cache is deployed in the Premium tier with 10 GB memory and geo-replication to a secondary region for disaster recovery. Misconfiguration: initially, they set TTL to 24 hours, causing stale prices during a flash sale. They reduced TTL to 5 minutes and added a cache invalidation trigger when prices are updated in the database.

Gaming Leaderboard

A gaming company uses Azure Cache for Redis to maintain real-time leaderboards for millions of players. Redis sorted sets (ZADD, ZRANK) allow O(log N) operations for updating scores and retrieving rankings. The cache runs in Standard tier with 5 GB memory. Players' scores are updated every few seconds, and the top 100 leaderboard is refreshed every 10 seconds. The cache reduces latency from 20 ms (if using SQL) to <1 ms. They also use Redis Pub/Sub to broadcast leaderboard changes to game servers. Performance consideration: they monitor evicted keys and adjust memory size to avoid frequent evictions of top players' data. Common mistake: using a single large sorted set for all players; they shard by game region to distribute load.

Session Store for Web Applications

A SaaS provider hosts a multi-tenant web application on Azure App Service. They use Azure Cache for Redis as a session state provider via the ASP.NET Redis Session State Provider. User session data (cart items, preferences) is stored in Redis with a 20-minute sliding expiration. This allows any web server instance to serve any user, enabling horizontal scaling. Without Redis, session data was stored in memory on each web server, causing session loss during scale-out or restarts. They chose Standard tier with 1 GB memory for 10,000 concurrent users. Misconfiguration: they initially used the Basic tier, which has no SLA and caused session loss during patching. They upgraded to Standard for high availability. They also set abortConnect=false in the connection string to prevent application crashes if Redis is temporarily unavailable.

How DP-900 Actually Tests This

DP-900 Objective Coverage

This topic falls under Domain 2: Relational Data (Objective 2.5: Describe how to handle non-relational data in Azure), but caching with Azure Cache for Redis is also relevant to Domain 1: Core Data Concepts (Objective 1.1: Describe core data concepts) and Domain 3: Analytics Workloads (Objective 3.3: Describe data visualization). Specifically, the exam tests:

Understanding of caching as a performance optimization technique.

Knowledge of the cache-aside pattern.

Default eviction policy (volatile-lru).

When to use Redis vs. other caching solutions.

Basic configuration: SSL port 6380, non-SSL 6379.

Tiers and their differences (Basic, Standard, Premium).

Common Wrong Answers and Why

1.

Choosing `allkeys-lru` as the default eviction policy: Many candidates assume Redis evicts any key when memory is full, but the default is volatile-lru, which only evicts keys with a TTL set. This is tested because it reflects a common misunderstanding.

2.

Assuming Redis persists data by default: Redis is an in-memory store; persistence is optional and only available in Premium tier. Many questions include a scenario requiring data durability and candidates incorrectly choose Standard tier.

3.

Thinking Redis supports SQL queries: Redis is NoSQL and does not support SQL. Candidates may confuse it with Azure SQL Database or Cosmos DB.

4.

Believing the cache is always consistent with the database: Caches can become stale. The exam tests understanding that TTL is used to manage staleness, and that cache invalidation is application responsibility.

Specific Values and Terms on the Exam

Default eviction policy: volatile-lru

SSL port: 6380, non-SSL: 6379

Premium tier features: persistence (RDB/AOF), clustering, geo-replication

Standard tier SLA: 99.9%

Maximum databases: 16

Cache-aside pattern: also called lazy loading

TTL: Time-to-Live

Edge Cases and Exceptions

Cache stampede: When many requests miss the cache simultaneously and all hit the database, causing a load spike. Solutions: use mutex locks or early expiration with background refresh.

Eviction under memory pressure: If memory is full and no keys are eligible for eviction (e.g., noeviction policy), write commands fail with OOM error.

Data loss on failover: In Standard tier, if the primary node fails, the replica becomes primary, but any data not persisted is lost. Premium tier with persistence reduces this risk.

How to Eliminate Wrong Answers

If a question mentions "durability" or "data survives a restart," rule out Basic and Standard tiers; only Premium offers persistence.

If a question asks for "lowest latency" or "in-memory cache," Redis is the answer, not Azure SQL or Cosmos DB.

If a question describes a pattern where the application checks cache first, then database, it's cache-aside.

If a question mentions "eviction policy" and "default," the answer is volatile-lru.

Key Takeaways

Azure Cache for Redis is an in-memory key-value store providing sub-millisecond data access.

The default eviction policy is volatile-lru (evicts keys with TTL using LRU).

Cache-aside (lazy loading) is the most common caching pattern: check cache, then database on miss, then store in cache.

Only Premium tier offers data persistence (RDB/AOF), clustering, and geo-replication.

Standard tier provides 99.9% SLA with primary/replica nodes.

SSL port is 6380; non-SSL port is 6379.

TTL (Time-to-Live) is used to expire stale data; default is no expiration.

Redis supports five basic data structures: strings, lists, sets, sorted sets, hashes.

Redis is single-threaded for command execution; use pipelining or clustering for high throughput.

Azure Cache for Redis is often used as a session store for web apps to enable horizontal scaling.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Azure Cache for Redis

In-memory key-value store with sub-millisecond latency

Supports various data structures: strings, lists, sets, sorted sets, hashes

No built-in persistence in Basic/Standard tiers

Best for caching, session store, real-time analytics

Scales horizontally via clustering (Premium)

Azure SQL Database with In-Memory OLTP

Relational database with in-memory tables (Hekaton) for faster access

Supports SQL queries and transactions

Full ACID compliance and durability

Best for transactional workloads requiring consistency

Scales vertically or via read replicas

Azure Cache for Redis

Fully managed Redis service

Sub-millisecond latency for cached data

Supports complex data structures and Lua scripting

Requires manual cache-aside implementation

Eviction policies and TTL to manage memory

Azure Cosmos DB with dedicated gateway caching

NoSQL database with integrated caching (dedicated gateway)

Latency ~1-2 ms with cache hit

Supports SQL-like queries (SQL API) and stored procedures

Automatic caching of frequently accessed data

No eviction policy; cache is bounded by gateway memory

Watch Out for These

Mistake

Azure Cache for Redis automatically syncs with the database.

Correct

Redis has no built-in awareness of the database. The application must implement cache-aside or write-through patterns to keep data consistent. Redis only stores what the application explicitly writes.

Mistake

Redis can be used as a primary database for all workloads.

Correct

Redis is an in-memory store with optional persistence. It is not designed for ACID transactions or complex queries. It is best used as a cache or session store, not as a primary data store for critical data.

Mistake

The default eviction policy is allkeys-lru.

Correct

The default eviction policy in Azure Cache for Redis is volatile-lru, which evicts keys with a TTL set using LRU. Keys without TTL are not evicted.

Mistake

All tiers of Azure Cache for Redis provide data persistence.

Correct

Only the Premium tier offers data persistence (RDB/AOF). Basic and Standard tiers are in-memory only and data is lost on node failure or restart.

Mistake

Redis supports SQL queries.

Correct

Redis is a NoSQL key-value store. It does not support SQL. Queries are based on key lookups or data structure operations (e.g., ZRANGEBYSCORE).

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the default eviction policy for Azure Cache for Redis?

The default eviction policy is `volatile-lru`. This means when memory is full, Redis evicts keys that have a TTL (time-to-live) set, using the Least Recently Used (LRU) algorithm. Keys without a TTL are never evicted under this policy. This is different from `allkeys-lru` which evicts any key regardless of TTL. On the exam, remember that the default is `volatile-lru`, not `allkeys-lru`.

How do I connect to Azure Cache for Redis from my application?

You connect using the hostname (e.g., `mycache.redis.cache.windows.net`) and either the primary or secondary access key. The SSL port is 6380 (recommended) and the non-SSL port is 6379. A typical connection string for the StackExchange.Redis client in C# is: `mycache.redis.cache.windows.net:6380,password=yourkey,ssl=True,abortConnect=False`. The `abortConnect=False` parameter prevents the application from crashing if the cache is temporarily unavailable. Always use SSL in production to encrypt data in transit.

What is the difference between Basic, Standard, and Premium tiers?

Basic tier is a single node with no SLA, suitable for development and testing. Standard tier has two nodes (primary/replica) with a 99.9% SLA, providing high availability. Premium tier includes all Standard features plus data persistence (RDB/AOF snapshots), clustering for scaling out, geo-replication for cross-region disaster recovery, and VNet injection for network isolation. Persistence and clustering are only available in Premium. For production workloads, use Standard or Premium depending on your durability and scale requirements.

What is the cache-aside pattern?

Cache-aside, also known as lazy loading, is the most common caching pattern. The application first checks the cache for the requested data. If found (cache hit), it returns the data directly. If not (cache miss), the application queries the database, stores the result in the cache with a TTL, and then returns it. This pattern ensures only frequently accessed data is cached, and stale data is automatically removed after TTL expires. It requires the application to handle cache misses and write to the cache explicitly.

Can Azure Cache for Redis be used as a primary database?

While Redis can be used as a primary data store for some use cases (e.g., session state, leaderboards), it is not recommended for transactional data that requires ACID guarantees or durability. In Azure Cache for Redis, only the Premium tier offers persistence, and even then, there is a risk of data loss during failover. For critical data, use Azure SQL Database or Cosmos DB as the primary store and Redis as a cache layer to improve performance.

What is the maximum number of databases in Azure Cache for Redis?

Redis supports 16 databases by default (indexed 0 to 15). You can select a database using the `SELECT` command. However, using multiple databases is generally discouraged because they share the same memory and eviction policies. For better isolation, use separate Redis instances. On the exam, remember that the default number of databases is 16.

How do I monitor cache performance?

Azure Cache for Redis provides metrics in the Azure portal, including Cache Hits, Cache Misses, Evicted Keys, Used Memory, and Server Load. A high cache hit ratio (e.g., >90%) indicates effective caching. You can also configure alerts for low hit ratios or high eviction rates. For deeper insights, enable Redis diagnostics with Azure Monitor and use the `INFO` command via the Redis CLI. Monitor network latency between your application and cache to ensure optimal performance.

Terms Worth Knowing

Ready to put this to the test?

You've just covered Azure Cache for Redis for Low-Latency Data — now see how well it sticks with free DP-900 practice questions. Full explanations included, no account needed.

Done with this chapter?