Prompt to Implement Real-Time WebSockets
A complete prompt to design and implement a real-time WebSocket architecture with connection management, authentication, scalability and monitoring.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un développeur backend expert en communication temps réel. Conçois une architecture WebSocket complète pour une application de [TYPE_APPLICATION] utilisant [TECHNOLOGIE_BACKEND] côté serveur et [TECHNOLOGIE_FRONTEND] côté client.
Spécifications techniques à couvrir :
-
Configuration du serveur WebSocket :
- Mise en place du serveur avec gestion des origines autorisées
- Middleware d'authentification sur la connexion (JWT ou session)
- Gestion du heartbeat/ping-pong pour détecter les connexions mortes
-
Gestion des connexions :
- Système de rooms/channels pour segmenter les flux
- Pool de connexions avec identifiants utilisateur
- Reconnexion automatique côté client avec backoff exponentiel
- Gestion propre de la déconnexion (cleanup des ressources)
-
Protocole de messages :
- Format standardisé des messages (type, payload, timestamp, id)
- Validation des messages entrants avec schéma
- Système d'acknowledgment pour garantir la réception
- File d'attente pour les messages envoyés pendant une déconnexion
-
Scalabilité :
- Stratégie pour plusieurs instances serveur (Redis pub/sub ou similaire)
- Gestion de la montée en charge ([NOMBRE_CONNEXIONS_SIMULTANEES] connexions simultanées)
- Rate limiting par utilisateur
-
Sécurité :
- Protection contre les attaques par flooding
- Validation et sanitization de tous les messages
- Timeout d'inactivité configurable
- Limitation de la taille des messages
-
Monitoring et debug :
- Logging structuré des événements de connexion/déconnexion
- Métriques (nombre de connexions actives, latence, messages/seconde)
- Endpoint de health check
Fournis le code complet côté serveur et côté client avec des commentaires expliquant chaque section. Inclus un exemple de test d'intégration pour valider le flux de connexion et d'échange de messages.
Personalize this prompt with Léa
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
<p>This prompt guides AI to produce a <strong>production-ready</strong> WebSocket architecture. It covers the six essential pillars of a robust real-time implementation: server configuration, connection management, message protocol, scalability, security and monitoring. Each section is detailed enough to avoid superficial responses.</p><p>To use it effectively, replace <strong>[APPLICATION_TYPE]</strong> with your specific use case (chat, dashboard, multiplayer game, notifications), <strong>[BACKEND_TECHNOLOGY]</strong> and <strong>[FRONTEND_TECHNOLOGY]</strong> with your stack (Node.js/Socket.io, Python/FastAPI, Go/Gorilla, etc.), and <strong>[CONCURRENT_CONNECTIONS]</strong> with your target load. The more precise these variables are, the more tailored the generated code will be.</p><p><strong>Advanced tip</strong>: after getting the base implementation, re-run the prompt adding specific constraints like <ul><li>user presence management (who is online)</li><li>offline mode support with synchronization</li><li>integration with an existing message broker (RabbitMQ, Kafka)</li></ul> to iterate toward a complete solution adapted to your context.</p>
Use Cases
Expected Output
Complete server and client code with WebSocket configuration, room management, typed message protocol, automatic reconnection, authentication, and integration tests. All commented and structured for production deployment.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- LéaAI
Pour fiabiliser l'acknowledgment, ajoutez un compteur de séquence côté client et serveur. Le client inclut `seq` dans chaque message ; le serveur retourne l'ack avec ce `seq`. En cas de reconnexion, le client demande le dernier `seq` reçu, ce qui permet de retransmettre uniquement les messages manquants et d'éviter les doublons (exactly-once delivery).
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Midjourney Prompt for Code Refactoring
Midjourney, renowned for its powerful image generation, finds an unexpected yet valuable application in code refactoring. By visualizing software architectures, flow diagrams, and abstract representations of data structures, Midjourney allows developers to conceptualize their refactoring before touching a single line of code. This visual approach helps identify complex dependencies, excessive coupling, and simplification opportunities that often remain invisible in a text editor. By generating clear architectural schemas, module maps, and before/after visualizations, technical teams can communicate more effectively about planned structural changes. Whether you are refactoring a monolith into microservices, reorganizing abstraction layers, or simplifying a legacy codebase, Midjourney transforms abstract concepts into concrete visual representations. This methodology is part of a growing trend of using visual tools to improve code quality and facilitate architectural decision-making within development teams.
Implement pod security
Enforce Kubernetes pod security
Configuration Management with GitOps
Implementing GitOps for configuration management
Write SLOs and SLIs
Define service reliability targets