キャッシュアサイド
データストアから必要な時にデータを読み込み、キャッシュに格納するパターンです。
構造と動作原理
矢印をステップごとに確認します。
キャッシュミス時は元データを読み、キャッシュに格納します。TTL、更新、無効化の方針が必要です。
期待できる効果
元データストアの遅延や競合を抑え、同時リクエストの処理性能を改善します。
トレードオフ
キャッシュとデータストアへの二重書き込みには不整合が起こり得るため、リトライと補正処理が必要です。
強い整合性が必要な場合、書き込み直後の読み込みが頻繁な場合、キャッシュミスのコストが高い場合には向きません。
運用・適用ガイド
総合説明であり、原文の裏付けがある項目とは区別しています。実環境で使用する前に検証してください。
使いどころ
商品カタログ、ユーザープロフィール、API レスポンスなど、読み込みが多く、短時間のデータの古さを許容できる場合に適します。
シナリオ
大規模な EC またはサプライチェーン基盤で1日に1億件の読み込みと5万件の書き込みがあります。商品・在庫の参照を P95 で100ms以内にし、元 DB の負荷を70%以上減らすのが目標です。ミス時に DB から読み込み、TTL を付けて Redis に格納します。在庫変更時にはキャッシュを無効化します。価格・在庫表示の5分以内の遅れは許容しますが、決済では元 DB の正本を参照します。
配置の原則
- アプリの近くにキャッシュアサイドの参照ロジックを置き、アプリと元 DB の間に共有 Redis を置く
- 静的・公開データはエッジ CDN、ユーザー別・ドメインデータはアプリのキャッシュに置く
- 元 DB を正本とし、TTL と無効化ポリシーでキャッシュを管理する
- Kubernetes ではアプリの Deployment、Redis の StatefulSet・Operator またはマネージドキャッシュ、CloudNativePG またはマネージド RDB を分ける
- ホットキーや大きなキーは別のキャッシュ層かシャーディングで分離する。
オンプレミス
オンプレミスでは Redis Sentinel や Cluster で高可用性を構成し、アプリ・キャッシュ・DB 間の通信遅延と障害ドメインを分離します。ミスの急増に備えコネクションプール、タイムアウト、ブレーカーを調整し、無効化・リトライ・監視を標準化します。
クラウド
ElastiCache、MemoryDB、Azure Cache for Redis などを Multi-AZ に配置し、VPC、セキュリティグループ、IAM は最小権限にします。マネージドでも接続設定・リトライ・タイムアウトを検証し、デプロイ前に DB フォールバックと容量保護を試験します。
Kubernetes
ステートレスなアプリを Deployment、HPA、PDB、readiness プローブで構成し、Redis は Operator、StatefulSet または外部のマネージドキャッシュに分離します。ConfigMap/Secret で接続を管理し、NetworkPolicy でアプリ・DB・キャッシュのアクセスを制限します。タイムアウト、ブレーカー、レート制限で DB を保護します。
障害対応
代表的な障害はキャッシュノード障害、大量 eviction、ホットキー、スタンピード、無効化漏れによる古いデータ、キャッシュと DB の二重書き込み不整合です。ヒット率、eviction、遅延、エラー、DB QPS を見ます。接続失敗はタイムアウト後にミスとして DB にフォールバックし、制限やブレーカーで過負荷を防ぎます。必要ならキャッシュを空にし一時的に TTL を短くして段階的にウォームアップし、原因と再発防止策を振り返ります。
14の観点別の根拠
調査時点の根拠の有無です。出典が正確で最新かどうかは別途判断してください。
定義・概要根拠あり
データストアから必要な時にデータを読み込み、キャッシュに格納するパターンです。
Load data on demand into a cache from a data store.解決する課題根拠あり
読み込みの多い処理で、同じレコードへの繰り返しアクセスによる元 DB の P95 遅延と負荷を抑えます。
Primary databases optimized for durability pay the full cost of a disk-based lookup on every request; as traffic grows, P95 latency degrades主要コンポーネント・リソース根拠あり
主な構成要素はアプリ、キャッシュ、元データストアです。アプリが後者2つへのアクセスを管理します。
Cache-Aside uses a cache alongside the source data store, with the application managing access to both.データ・アセットの配置根拠あり
読み込みに最適化した Web 層の前にエッジ CDN、後段にアプリのキャッシュアサイド層と DB を置く構成です。
A read-optimized web tier fronts the database with an edge CDN and application cache-aside layer.代表的なユースケース根拠あり
商品カタログ、ユーザープロフィール、API レスポンスのように繰り返し読み込むデータに適します。
Read-heavy workloads (product catalogs, user profiles, API responses) hit the same records thousands of times between updates.シナリオ例根拠あり
例として、サプライチェーン・計画プラットフォームの読み込み最適化 Web アーキテクチャが挙げられます。
Design a Kubernetes architecture for a Supply Chain & Planning platform using the Cache-Aside Read-Heavy Web pattern.不向きな状況・注意点根拠あり
強い整合性が必要な場合、書き込み直後の読み込みが頻繁な場合、キャッシュミスのコストが高い場合には向きません。
You need strong consistency between cache and databaseオンプレミス(開発・デプロイ・運用)未確認
確認済みの原文根拠はありません。このパターンが不適合であるという意味ではありません。
クラウド(開発・デプロイ・運用)根拠あり
クラウドのマネージドキャッシュでもクライアント設定ミスで障害が繰り返されるため、接続設定、リトライ、タイムアウトを検証します。
a small number of client-side misconfigurations in how applications connected to ElastiCache were causing repeated disruptions.Kubernetes(開発・デプロイ・運用)根拠あり
Kubernetes ではキャッシュアサイドのアプリを Deployment とし、Redis、DB、Ingress や CDN と組み合わせられます。
Design a Kubernetes architecture for a Supply Chain & Planning platform using the Cache-Aside Read-Heavy Web pattern.障害対応根拠あり
Redis に接続できない場合はユーザーにエラーを返さず、DB に透過的にフォールバックします。
If the Redis connection fails, the application must transparently fall back to the database instead of returning an error to the user.長所根拠あり
元データストアの遅延や競合を抑え、同時リクエストの処理性能を改善します。
Caching reduces the latency and contention that are associated with handling large volumes of concurrent requests in the original data store.短所・トレードオフ根拠あり
キャッシュとデータストアへの二重書き込みには不整合が起こり得るため、リトライと補正処理が必要です。
Imagine that you’ve successfully updated the cache but the datastore fails to update. The code needs to implement retries.その他の参考文献 (23)
- Cache-Aside Pattern - Azure Architecture Center | Microsoft Learn ↗
- Redis cache-aside ↗
- Caching Best Practices | Amazon Web Services ↗
- How to use Redis for Query Caching ↗
- Cache-Aside ↗
- Cache-Aside Pattern (Lazy Loading) - Redis Patterns ↗
- A Hitchhiker's Guide to Caching Patterns ↗
- The Architect's Guide to Common Caching Patterns ↗
- Caching Guidance - Azure Architecture Center ↗
- Deploy Amazon EKS clusters across cloud and on-premises environments - Amazon EKS ↗
- How to Run Kubernetes Across On-Premises and Public Cloud: Four Hybrid Architecture Models and the Seven Layers to Standardize ↗
- Supply Chain & Planning — Cache-Aside Read-Heavy Web (Kubernetes) — Architecture Diagram Template ↗
- Reference Architecture: GKE Enterprise hybrid environment - part 2 - Dec '24 - Google Docs ↗
- Deploy Containerized Apps with AKS Hybrid and Edge by Using GitOps - Azure Architecture Center | Microsoft Learn ↗
- Understanding the Cache-Aside Pattern: A Practical Guide | by Mallikarjuna Mallesha ↗
- Kubernetes Deployment Options for On-Prem Clusters ↗
- How Intuit and AWS systematically improved resiliency on ElastiCache using AWS Fault Injection Service | AWS Database Blog ↗
- When the cache fails: fail-open, fail-closed and the cascade | ShardCraft ↗
- Google SRE - Cascading Failures: Reducing System Outage ↗
- Implementing the Cache-Aside Pattern Correctly ↗
- Cache-Aside | Engineer Atlas ↗
- Design a distributed cache · Stanley Jacob ↗
- Cache Invalidation: TTLs, Write Paths, and the Thundering Herd | Scixa ↗