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

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

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

💻DeveloppementIntermediateAll AIs

Set up semantic versioning automation

Automate semantic versioning

0254
💻DeveloppementIntermediateAll AIs

Write Comprehensive Unit Tests

Generate an exhaustive unit test suite covering nominal cases, edge cases, and errors with appropriate mocks.

22562
💻DeveloppementIntermediateAll AIs

Improve Test Coverage

Strategically increase test coverage

0264
💻DeveloppementIntermediateAll AIs

Perplexity Prompt to Create a REST API

Perplexity AI stands out from other AI assistants by its unique ability to combine real-time web search and code generation. For creating a REST API, this advantage is significant: Perplexity can check the latest framework versions, verify current security best practices, and rely on the most recent official documentation. Unlike a classic LLM whose knowledge is fixed, Perplexity guarantees recommendations aligned with the state of the art. Whether you are building an API with Node.js/Express, Python/FastAPI, or any other stack, a well-structured prompt allows you to obtain a complete architecture, consistent endpoints, robust error handling, and test examples. The challenge is to formulate your request with enough business context and technical constraints so that Perplexity generates production-grade code, not just a tutorial. This guide provides optimized prompts to get the most out of Perplexity in designing professional REST APIs, from beginner to advanced versions.

0252