P
💻DeveloppementAdvancedAll AIs

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 :

  1. 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
  2. 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)
  3. 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
  4. 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
  5. 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
  6. 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

Create a real-time chat with rooms and typing indicatorsDevelop a monitoring dashboard with live metric updatesImplement an instant push notification systemBuild a collaborative editor with real-time synchronization

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 Optimizer

Comments

  • 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

💻DeveloppementBeginnerAll AIs

Post-Deployment Smoke Tests

Automatically validate a deployment

0134
💻DeveloppementBeginnerAll AIs

Convert CSS to Tailwind

Migrate styling to Tailwind

0147
💻DeveloppementAdvancedAll AIs

Terraform Multi-Environment Architecture

Managing multiple environments with Terraform

0130
💻DeveloppementIntermediateAll AIs

Multi-Level Testing Pipeline

Structuring tests in the pipeline

0144