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
Answer 3 questions and Léa tailors the prompt to your situation.
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.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt GuideComments
Be the first to comment on this prompt.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Similar Prompts
Implement property-based testing
Add property-based tests
Mistral Prompt for Creating a REST API
Mistral, the leading French AI model, excels at generating structured and performant backend code. Creating a complete REST API represents a technical challenge that involves defining routes, handling HTTP requests, validating data, connecting to a database, and setting up a maintainable architecture. With a well-crafted prompt, Mistral can generate the entire skeleton of a functional REST API in seconds, adhering to the conventions of the chosen framework and development best practices. Whether you're using Express.js, FastAPI, Flask, or Spring Boot, a precise prompt delivers production-ready code with error handling, authentication middleware, and integrated Swagger documentation. The prompt engineering approach transforms Mistral into a true backend development assistant, capable of producing coherent, tested, and documented code. This page guides you in formulating the optimal prompt based on your skill level and technical needs.
Helm Chart for Application
Create a Helm chart
Complete Curriculum-Aligned Lesson Plan
Quickly prepare a structured lesson