Create a High-Performance Scalable Redis Cache System
A complete prompt to design and implement a Redis cache system with invalidation strategies, error handling and monitoring.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un architecte backend senior spécialisé en systèmes distribués et en optimisation de performance. Conçois un système de cache Redis complet pour mon application.
Contexte technique
- Langage / Framework : [LANGAGE_ET_FRAMEWORK] (ex : Node.js/Express, Python/FastAPI, Java/Spring Boot)
- Type d'application : [TYPE_APPLICATION] (ex : e-commerce, SaaS multi-tenant, API publique, réseau social)
- Base de données principale : [BASE_DE_DONNEES] (ex : PostgreSQL, MongoDB, MySQL)
- Volume estimé : [NOMBRE_REQUETES_PAR_SECONDE] requêtes/seconde en pic
- Infrastructure : [INFRASTRUCTURE] (ex : AWS ElastiCache, Redis auto-hébergé, Docker Compose, Kubernetes)
Ce que je veux
-
Architecture du cache :
- Propose une stratégie de cache adaptée (Cache-Aside, Read-Through, Write-Through, Write-Behind) en justifiant ton choix
- Définis la structure des clés Redis avec un naming convention clair (préfixes, séparateurs, versioning)
- Recommande les structures de données Redis appropriées (String, Hash, Set, Sorted Set, Stream) pour chaque type de donnée à cacher
-
Implémentation complète :
- Écris une classe/module de cache réutilisable avec : connexion (pool), get, set, delete, invalidation par pattern
- Implémente le pattern Cache-Aside avec gestion du cache stampede (mutex/lock)
- Ajoute un mécanisme de sérialisation/désérialisation (JSON, MessagePack ou Protocol Buffers)
- Gère les erreurs gracieusement : si Redis tombe, l'application doit continuer à fonctionner (circuit breaker)
-
Stratégie d'invalidation :
- Définis des TTL adaptés par type de ressource (données chaudes vs froides)
- Implémente l'invalidation par tags/groupes (ex : invalider tout le cache d'un utilisateur)
- Propose un mécanisme de cache busting pour les déploiements
- Gère la cohérence cache/base de données avec un pattern événementiel si pertinent
-
Patterns avancés :
- Rate limiting basé sur Redis (sliding window)
- Cache distribué avec Redis Cluster ou Sentinel (si pertinent pour le volume)
- Mise en cache de sessions utilisateur
- Cache de résultats de requêtes complexes avec invalidation intelligente
-
Monitoring et observabilité :
- Métriques à suivre : hit ratio, latence, mémoire utilisée, évictions
- Intègre un système de logging des opérations cache (hit/miss/error)
- Propose une configuration d'alertes
-
Configuration Redis :
- Fichier redis.conf optimisé pour mon cas d'usage
- Politique d'éviction recommandée (allkeys-lru, volatile-ttl, etc.)
- Configuration mémoire et persistence (RDB/AOF)
Fournis le code complet, commenté, avec des tests unitaires pour les composants critiques. Inclus un fichier Docker Compose pour l'environnement de développement avec Redis.
Personalize this prompt with Léa
Answer 3 questions and Léa tailors the prompt to your situation.
Why this prompt works
<p>This prompt guides AI to produce a production-quality Redis cache system. By specifying your <strong>language/framework</strong>, <strong>application type</strong> and <strong>infrastructure</strong>, you get code directly integrable into your project, not a generic tutorial.</p><p>The prompt structure covers the five pillars of a robust cache: <strong>architecture</strong> (which strategy for which need), <strong>implementation</strong> (reusable code with error handling), <strong>invalidation</strong> (the most complex caching problem), <strong>advanced patterns</strong> (rate limiting, sessions) and <strong>monitoring</strong>. Each section forces the AI to justify its technical choices rather than proposing a default solution.</p><p>For better results, be specific about your <strong>variables</strong>: a cache for a REST API at 100 req/s is nothing like a cache for an e-commerce site at 10,000 req/s. Also specify your constraints (budget, team, existing technical debt). You can iterate by asking to dive deeper into a specific section, for example <strong>"Detail the tag-based invalidation part with concrete examples for my data model"</strong>.</p>
Use Cases
Expected Output
A complete Redis cache system including: reusable cache module source code in your language, optimized Redis configuration file, development Docker Compose, unit tests, and documentation of key naming conventions and invalidation strategies.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
Be the first to comment on this prompt.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Create Your First API with Express.js
Learn to create your first Express.js REST API from A to Z with pedagogical explanations adapted to beginners.
Implement pod security
Enforce Kubernetes pod security
Build a virtualized list
Handle massive data lists
Prometheus Configuration and Alerts
Set up Prometheus monitoring