Databases 10 min read

Boost High‑Traffic Services with Redis: Local & Remote Caching Strategies

This article explains how to use Redis as a high‑performance caching layer—covering local and remote caches, support for multiple data structures, expiration and eviction policies, persistence mechanisms like RDB and AOF, a simple TCP protocol, and advanced modules—enabling services to handle tens of thousands of queries per second without overloading MySQL.

macrozheng
macrozheng
macrozheng
Boost High‑Traffic Services with Redis: Local & Remote Caching Strategies

Local Cache

Querying memory is much faster than querying disk. By storing product data in an in‑process dictionary (a map), the service can retrieve items directly from memory, falling back to MySQL only when a cache miss occurs, dramatically reducing query latency.

The key is the product ID and the value is the product data; subsequent requests for the same ID are served from the local cache.

Remote Cache

To avoid duplicating caches across multiple service instances, the dictionary is extracted into a separate remote cache service. All instances read and write through this service, eliminating redundant memory usage.

Concurrent access is handled by funneling all read/write commands into a single thread, removing concurrency issues and thread‑switch overhead.

Support for Multiple Data Types

The cache service now supports not only strings but also FIFO queues (List), sets for deduplication, sorted sets (ZSet) for ranking, expanding its capabilities beyond simple key‑value storage.

Memory Expiration Strategy

Each cached entry can be assigned an expiration time. When the time elapses, the entry is automatically removed, preventing unbounded memory growth. Clients decide appropriate TTLs via the EXPIRE command.

Cache Eviction

When memory approaches its limit, eviction policies such as LRU (Least Recently Used) discard less‑frequently accessed data, keeping the cache hot and efficient.

Persistence

To survive restarts, the cache periodically snapshots the entire dataset to disk (RDB). Additionally, an Append‑Only File (AOF) logs every write operation, ensuring near‑real‑time durability. AOF files are compacted through rewrite operations.

Simplified Network Protocol

Instead of HTTP, the service uses a lightweight TCP protocol where commands like SET key value and GET key are sent directly, minimizing overhead. The official redis‑cli tool can interact with the server without custom code.

What Is Redis?

Redis (Remote Dictionary Server) is a high‑performance, in‑memory data store that supports multiple data types, rich eviction policies, and persistence options, making it a versatile caching solution for demanding applications.

Summary

Redis is essentially a remote dictionary service where all core read/write logic runs in a single thread, eliminating concurrency problems.

It supports multiple data structures, expiration policies, and eviction strategies, providing a simple yet powerful caching layer.

Persistence is achieved via RDB snapshots and AOF logs, ensuring data survives restarts.

Extensible modules such as RediSearch, RedisJSON, RedisGraph, and RedisTimeSeries broaden its capabilities beyond basic caching.

performanceDatabaseRediscachingPersistenceData Structures
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.