<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Houdaifa Drahm</title>
    <description>The latest articles on DEV Community by Houdaifa Drahm (@houdaifa_drahm).</description>
    <link>https://dev.to/houdaifa_drahm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4259649%2Fec1974eb-e312-4371-9946-e10e535223bd.jpg</url>
      <title>DEV Community: Houdaifa Drahm</title>
      <link>https://dev.to/houdaifa_drahm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/houdaifa_drahm"/>
    <language>en</language>
    <item>
      <title>Building an HTTP Server in C++ with Nonblocking I/O and epoll</title>
      <dc:creator>Houdaifa Drahm</dc:creator>
      <pubDate>Mon, 23 Nov 2026 04:43:52 +0000</pubDate>
      <link>https://dev.to/houdaifa_drahm/building-an-http-server-in-c-with-nonblocking-io-and-epoll-f84</link>
      <guid>https://dev.to/houdaifa_drahm/building-an-http-server-in-c-with-nonblocking-io-and-epoll-f84</guid>
      <description>&lt;p&gt;By &lt;a href="https://houdaifa.dev/" rel="noopener noreferrer"&gt;Houdaifa Drahm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An HTTP server has to turn an arbitrary stream of bytes into complete requests while serving more than one client. A browser can send half a request and go quiet. A client can read a response slowly enough that only part of it fits in the socket buffer. A useful server makes progress on other connections in both situations.&lt;/p&gt;

&lt;p&gt;This guide builds the design in stages. Start with a static file on one listener. Then add incremental HTTP parsing, buffered writes, routing, uploads, and CGI. The examples use C++98-friendly data structures and Linux networking APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  What epoll actually tells you
&lt;/h2&gt;

&lt;p&gt;On Linux, create an epoll instance, use &lt;code&gt;epoll_ctl()&lt;/code&gt; to register or modify the descriptors you care about, and call &lt;code&gt;epoll_wait()&lt;/code&gt; to obtain ready events. The kernel maintains an interest list and a ready list. The program still has to accept connections, read bytes, interpret HTTP, and send a response. Readiness is a signal that an operation can make progress, and the result of the operation tells you how much actually happened. &lt;a href="https://man7.org/linux/man-pages/man7/epoll.7.html" rel="noopener noreferrer"&gt;Linux epoll manual&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Register the listener for input readiness. Its readable event means a connection is waiting to be accepted. A readable event on an accepted socket instead means there may be incoming bytes or an end-of-stream condition. Keep both kinds of descriptors nonblocking. A client socket usually has read interest when it is waiting for input. Give it write interest when a response has queued bytes and remove write interest when the output drains. A healthy TCP socket is often writable, so subscribing to write events when there is nothing to send can make the loop spin. &lt;a href="https://man7.org/linux/man-pages/man2/accept.2.html" rel="noopener noreferrer"&gt;accept(2)&lt;/a&gt; · &lt;a href="https://man7.org/linux/man-pages/man2/recv.2.html" rel="noopener noreferrer"&gt;recv(2)&lt;/a&gt; · &lt;a href="https://man7.org/linux/man-pages/man2/send.2.html" rel="noopener noreferrer"&gt;send(2)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Start with level-triggered epoll. While a descriptor remains ready, the loop can be notified again. Edge-triggered mode changes the notification contract. If you leave unread data behind after an edge, you may wait for another transition that never comes. It is easier to validate connection state and HTTP framing with level-triggered readiness first. On macOS, use a Linux VM or container if you want to learn epoll specifically. A native macOS implementation can use &lt;code&gt;kqueue&lt;/code&gt; with &lt;code&gt;kevent()&lt;/code&gt; or use &lt;code&gt;poll()&lt;/code&gt; for a portable starting point. The connection and parser model can stay the same even when the event API changes. &lt;a href="https://man7.org/linux/man-pages/man7/epoll.7.html" rel="noopener noreferrer"&gt;Linux epoll manual&lt;/a&gt; · &lt;a href="https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/kqueue.2.html" rel="noopener noreferrer"&gt;Apple kqueue manual&lt;/a&gt; · &lt;a href="https://man7.org/linux/man-pages/man2/poll.2.html" rel="noopener noreferrer"&gt;poll(2)&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the unfinished work on each connection
&lt;/h2&gt;

&lt;p&gt;Give each accepted socket a connection object. Keep the unread input, parser state, pending output, output offset, and a deadline together. If the response streams a file, also track the file descriptor and how much of it remains. If it runs CGI, keep the child process and pipe state with the same request. In C++98, a map keyed by file descriptor is enough to learn this design.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Listener ready    -&amp;gt; accept and register a client
Client readable   -&amp;gt; append bytes and advance the parser
Request complete  -&amp;gt; choose a route and queue a response
Client writable   -&amp;gt; send pending bytes and advance the offset
Response drained  -&amp;gt; read another request or close the connection
Timeout or error  -&amp;gt; unregister descriptors and release resources
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An event can contain more than one readiness flag. If handling one flag closes the connection, check that the entry still exists before using it for another flag. Make cleanup close the client and any files or pipes the connection owns. Keep deadlines for clients waiting on headers, bodies, output, or scripts so a connection cannot wait indefinitely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parse a stream in stages
&lt;/h2&gt;

&lt;p&gt;The browser sends HTTP messages over a TCP byte stream. A single call to &lt;code&gt;recv()&lt;/code&gt; yields the bytes that are available, which may be less than one request or more than one request. Give the parser an explicit incomplete result. If the request line or headers end halfway through a read, preserve the bytes and resume on the next read. Reserve a parse error for invalid syntax, invalid framing, or a limit that has been exceeded. &lt;a href="https://www.rfc-editor.org/rfc/rfc9112.html#section-2" rel="noopener noreferrer"&gt;RFC 9112 sections 2–4&lt;/a&gt; · &lt;a href="https://man7.org/linux/man-pages/man2/recv.2.html" rel="noopener noreferrer"&gt;recv(2)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Start the parser with the request line, header fields, and the blank line that terminates them. Compare header names case-insensitively. After the headers, make one explicit decision about how the body is framed. A valid &lt;code&gt;Content-Length: 12&lt;/code&gt; means the parser needs exactly 12 body bytes. If the current buffer contains five, wait for seven more. If it contains more than 12, preserve the extra bytes for the next message when the connection is reusable. &lt;a href="https://www.rfc-editor.org/rfc/rfc9110.html#section-5.1" rel="noopener noreferrer"&gt;RFC 9110 section 5.1&lt;/a&gt; · &lt;a href="https://www.rfc-editor.org/rfc/rfc9112.html#section-6" rel="noopener noreferrer"&gt;RFC 9112 section 6&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For chunked bodies, parse a hexadecimal size, collect that many data bytes, consume the delimiter, and repeat. A zero-size chunk ends the data and is followed by the trailer section and its terminator. Apply size limits to headers and decoded body data, and check lengths before allocating memory. Keep conflicting or invalid framing out of the route handler. For a small server, rejecting a request that supplies both Transfer-Encoding and Content-Length and closing the connection is the simplest conservative choice. &lt;a href="https://www.rfc-editor.org/rfc/rfc9112.html#section-6.3" rel="noopener noreferrer"&gt;RFC 9112 section 6.3&lt;/a&gt; · &lt;a href="https://www.rfc-editor.org/rfc/rfc9112.html#section-7.1" rel="noopener noreferrer"&gt;RFC 9112 section 7.1&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Route only after the protocol has been parsed
&lt;/h2&gt;

&lt;p&gt;A useful route table answers four questions. Which listener accepted the connection? Which route prefix matches the request path under your configuration rules? Which methods are allowed? Where does the resource live? Parse the configuration at startup so the event loop can work with validated listener and route records. For prefix-based routing, test segment boundaries so a route such as &lt;code&gt;/images&lt;/code&gt; does not accidentally match &lt;code&gt;/images-old&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Start with GET for a known static file. Then handle directory indexes, redirects, and errors. Add POST on a route that accepts uploads and applies a body limit. Keep uploaded files under a designated storage directory and choose safe server-side filenames. Add DELETE only for routes where deletion is intended. Keep filesystem resolution inside the configured root and give custom error pages a built-in fallback. When a method is disallowed for a resource, an HTTP 405 response includes an Allow header. &lt;a href="https://www.rfc-editor.org/rfc/rfc9110.html#section-9" rel="noopener noreferrer"&gt;RFC 9110 on methods&lt;/a&gt; · &lt;a href="https://www.rfc-editor.org/rfc/rfc9110.html#section-15.5.6" rel="noopener noreferrer"&gt;RFC 9110 on 405&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Send every response through a buffer
&lt;/h2&gt;

&lt;p&gt;Serialize the status line and headers into the output queue. For a first implementation, use a known Content-Length for static files and fixed response bodies. Use the same send path for headers, generated bodies, and file chunks. On a writable event, send from the current offset. A positive return value advances that offset by the reported byte count. If a call accepts 3,000 bytes from an 8,192-byte chunk, keep the remaining 5,192 bytes pending. Load the next chunk after that suffix has drained. &lt;a href="https://man7.org/linux/man-pages/man2/send.2.html" rel="noopener noreferrer"&gt;send(2)&lt;/a&gt; · &lt;a href="https://www.rfc-editor.org/rfc/rfc9112.html#section-6" rel="noopener noreferrer"&gt;RFC 9112 message framing&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bound the amount of work you do for one connection per loop turn. Otherwise a fast client with a large response can keep the loop busy while smaller responses wait. A simple first version deliberately closes after each response and sends &lt;code&gt;Connection: close&lt;/code&gt;. Add persistent connections once you have verified both write completion and preservation of any unread input for the next request. &lt;a href="https://www.rfc-editor.org/rfc/rfc9112.html#section-9.3" rel="noopener noreferrer"&gt;RFC 9112 section 9.3&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Treat CGI as a second I/O pipeline
&lt;/h2&gt;

&lt;p&gt;CGI launches a configured program for a request. The server builds its environment, provides the body through standard input, and reads the program’s headers and body from standard output. For a POST request with chunked transfer coding, decode the body before sending it to the program. Close the input pipe when all request bytes have been supplied so the program can observe EOF. Parse the CGI output before converting it to an HTTP response. The program’s stdout is not necessarily a complete HTTP response with its own status line. &lt;a href="https://www.rfc-editor.org/rfc/rfc3875.html" rel="noopener noreferrer"&gt;RFC 3875 sections 4 and 6&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Track the parent ends of the CGI pipes in the same readiness loop as the client sockets. The child may start producing output before it has consumed all of its input. If the parent blocks writing input while the output pipe fills, both sides can wait on each other. Handle reading and writing independently, enforce a script deadline, and reap the child after it exits. Start with a script that prints one fixed response before testing a script that reads a small POST body.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test one boundary at a time
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Send a static GET to a loopback listener with &lt;code&gt;curl -i http://127.0.0.1:8080/&lt;/code&gt;. Check the status, headers, and file bytes before adding more routes.&lt;/li&gt;
&lt;li&gt;Feed the same valid request to your parser in progressively larger fragments. Put splits inside the request line, inside a header, between the two bytes of a CRLF, and inside a body. Expect incomplete results until the corresponding message boundary is reached.&lt;/li&gt;
&lt;li&gt;Test an ordinary chunked upload. Confirm that the bytes stored on disk match the decoded body and that the next request begins at the correct byte when you reuse the connection.&lt;/li&gt;
&lt;li&gt;Download a large file slowly and compare its checksum with the original. Add a test harness that limits each send so your pending-output code runs even on a fast loopback connection. While the download is running, verify that a second client can fetch a small file.&lt;/li&gt;
&lt;li&gt;Close a client during a response and verify that the loop releases the socket and output file. Then give a local CGI script a short deadline and check that a second client stays responsive if the script does not finish.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The most useful debugging information is the connection’s current state. Log when it becomes readable, how many bytes the parser has, how many output bytes remain, and which phase owns the next deadline. That is enough to see whether the failure belongs to the protocol parser, the selected route, or the event loop.&lt;/p&gt;

&lt;p&gt;For a concrete repository to read alongside this guide, see &lt;a href="https://github.com/Houdaifa1/webserv" rel="noopener noreferrer"&gt;Webserv source code&lt;/a&gt;. Trace its event loop, request parser, and response handler, then compare each one with the incremental design above.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>linux</category>
      <category>networking</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building a Real-Time Multiplayer Game with NestJS and Socket.IO</title>
      <dc:creator>Houdaifa Drahm</dc:creator>
      <pubDate>Mon, 23 Nov 2026 04:43:29 +0000</pubDate>
      <link>https://dev.to/houdaifa_drahm/building-a-real-time-multiplayer-game-with-nestjs-and-socketio-nmb</link>
      <guid>https://dev.to/houdaifa_drahm/building-a-real-time-multiplayer-game-with-nestjs-and-socketio-nmb</guid>
      <description>&lt;p&gt;By &lt;a href="https://houdaifa.dev/" rel="noopener noreferrer"&gt;Houdaifa Drahm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A real-time game needs more than a browser that can draw a puck. Two players must be authenticated, matched, assigned sides, and kept in sync even when their network connections behave differently. A match also needs a clear ending, a record for history, and a deployment that supports WebSocket connections.&lt;/p&gt;

&lt;p&gt;This guide starts with one two-player air hockey match and grows it into a full-stack application. It uses NETPONG as a source-code reference while describing a design you can build and test independently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why NestJS fits this application
&lt;/h2&gt;

&lt;p&gt;NestJS gives the HTTP API, the WebSocket gateway, and the game service explicit places to live. A controller handles HTTP requests, a gateway receives or sends socket events, and an injectable service owns application logic. Modules declare which providers they own and which dependencies they import. The main benefit is that game rules can be tested through a service without needing a real socket or browser. &lt;a href="https://docs.nestjs.com/modules" rel="noopener noreferrer"&gt;NestJS modules&lt;/a&gt; · &lt;a href="https://docs.nestjs.com/providers" rel="noopener noreferrer"&gt;NestJS providers&lt;/a&gt; · &lt;a href="https://docs.nestjs.com/websockets/gateways" rel="noopener noreferrer"&gt;NestJS gateways&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The NETPONG backend is organized around features. The root module assembles authentication, users, chat, game, email, health, and metrics, alongside configuration and the PostgreSQL connection. The game module registers its controller, gateway, and service. It imports the user and metrics modules and registers the match entity with TypeORM. This example shows the shape of the code to look for. The filenames are representative, with the supporting modules shortened for readability.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
  main.ts             Application bootstrap and shared middleware
  app.module.ts       Root module and infrastructure wiring
  auth/               Sign-in, tokens, and authentication guards
  user/               Profiles, friends, blocking, search, and statistics
  chat/               Chat gateway, conversation service, and message model
  game/
    game.module.ts    Feature dependencies and providers
    game.controller.ts  HTTP endpoints for game records and statistics
    game.gateway.ts     Socket events and delivery
    game.service.ts     Matchmaking, sessions, and simulation
    entities/          Persisted match records
    dto/               Event payload definitions
  email/              Email delivery support
  health/             Health endpoints
  metrics/            Application counters and gauges
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use that structure to decide where code goes. An HTTP endpoint for match history belongs in the controller. The gateway handles a movement message and obtains the authenticated identity. The service decides whether the player belongs to the match and updates the game state. A database repository persists the result. When a gateway starts carrying the scoring rules, it becomes difficult to test the game without also testing Socket.IO. &lt;a href="https://github.com/fttranscendenceorganization/ft_transcendence/blob/43ed8209a9f4af2fad9d1520ede295986ab0c339/backend_srcs/src/app.module.ts" rel="noopener noreferrer"&gt;NETPONG root module&lt;/a&gt; · &lt;a href="https://github.com/fttranscendenceorganization/ft_transcendence/blob/43ed8209a9f4af2fad9d1520ede295986ab0c339/backend_srcs/src/game/game.module.ts" rel="noopener noreferrer"&gt;NETPONG game module&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Authenticate the connection and validate its events
&lt;/h2&gt;

&lt;p&gt;Start with accounts and sign-in. Store password hashes with a dedicated password-hashing algorithm. For socket connections, authenticate the handshake, then associate the connection with a stable user ID. A socket ID identifies the current connection and may change when the browser reconnects. Use the authenticated user ID for ownership and the socket or room membership for delivery. &lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html" rel="noopener noreferrer"&gt;OWASP Password Storage Cheat Sheet&lt;/a&gt; · &lt;a href="https://socket.io/docs/v4/server-socket-instance/" rel="noopener noreferrer"&gt;Socket.IO server socket instance&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Validate a socket event at the transport boundary and authorize it at the feature boundary. A movement message needs finite numeric coordinates. Its sender also needs to belong to the active match and control one paddle in it. Test both conditions. A valid payload by itself does not imply that the user is allowed to act on a particular match. Nest gateways support pipes, so a DTO and a WebSocket-aware validation path can make malformed payloads fail before they reach the simulation. &lt;a href="https://docs.nestjs.com/websockets/pipes" rel="noopener noreferrer"&gt;NestJS WebSocket pipes&lt;/a&gt; · &lt;a href="https://docs.nestjs.com/websockets/guards" rel="noopener noreferrer"&gt;NestJS WebSocket guards&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Match two players before starting the game
&lt;/h2&gt;

&lt;p&gt;Keep a queue per mode. When two eligible players are waiting, take them out of the queue and create one match record in memory with a match ID, the two user IDs, their sides, and an initial state. A player should belong to at most one queue or active match at a time. Make repeated queue requests safe, since a retry or double click can send the same intent twice.&lt;/p&gt;

&lt;p&gt;Give the match a readiness phase. Notify both clients that a match was found, and wait for each to finish loading and signal ready. Define what happens if either player leaves before it starts. A practical policy is to expire the invitation and let the remaining player rejoin the queue. Choose a separate policy for a disconnect in the middle of a match, such as a short reconnection window followed by a forfeit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Both clients     -&amp;gt; join the same mode queue
Server           -&amp;gt; assigns one match ID and a side to each player
Both clients     -&amp;gt; signal readiness after loading
Server           -&amp;gt; runs the match and broadcasts state
Clients          -&amp;gt; send input and render received state
Server           -&amp;gt; ends the match, publishes the result, saves history
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Socket.IO rooms are an easy way to send state to members of a match. Join the room on the server after checking membership. NETPONG’s example delivers match state directly to the two current socket IDs. Either approach can work in a single server process. A Socket.IO room groups recipients. The match state and its rules still belong to the game service. &lt;a href="https://socket.io/docs/v4/rooms/" rel="noopener noreferrer"&gt;Socket.IO rooms&lt;/a&gt; · &lt;a href="https://github.com/fttranscendenceorganization/ft_transcendence/blob/43ed8209a9f4af2fad9d1520ede295986ab0c339/backend_srcs/src/game/game.gateway.ts" rel="noopener noreferrer"&gt;NETPONG game gateway&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the simulation authoritative
&lt;/h2&gt;

&lt;p&gt;Clients send input. The server owns paddle positions, puck motion, collisions, scoring, and the winner. In air hockey, one client message can set a target position. At each simulation step, clamp that target to the player’s side and move the actual paddle toward it by a bounded distance. Apply the same rules regardless of how often a browser sends messages. This makes scoring decisions consistent across the two clients and gives the simulation a small set of rules to test.&lt;/p&gt;

&lt;p&gt;Run simulation on a deliberate tick schedule and measure elapsed time or use a fixed-step accumulator. Browser rendering and server simulation are separate clocks. Limit catch-up work after a stall so one slow event-loop turn does not produce an unbounded amount of work on the next turn. Start by sending snapshots with a match ID, sequence or tick number, positions, and score. Measure payload size and latency before adding delta compression. &lt;a href="https://github.com/fttranscendenceorganization/ft_transcendence/blob/43ed8209a9f4af2fad9d1520ede295986ab0c339/backend_srcs/src/game/game.service.ts" rel="noopener noreferrer"&gt;NETPONG game service&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the client, keep the latest snapshot outside the React render path if updates are frequent. Use a draw loop to render on a canvas with &lt;code&gt;requestAnimationFrame()&lt;/code&gt;. Convert pointer coordinates to the same logical space on every screen size. Once a basic client works, experiment with interpolation between buffered snapshots and measure the visual smoothness against the extra display delay. Keep buttons, text, and match results in normal UI components. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame" rel="noopener noreferrer"&gt;MDN requestAnimationFrame&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Design reconnection and match history as separate paths
&lt;/h2&gt;

&lt;p&gt;Socket.IO preserves message order, and its default delivery guarantee is at most once. A disconnected client can miss events. On reconnection, authenticate the user again, check the match membership, and provide a current snapshot. A client should be able to resume from that snapshot even if it missed several movement or score messages. Socket.IO offers connection state recovery where supported, but the application still needs a recovery path for cases where it cannot restore the session. &lt;a href="https://socket.io/docs/v4/delivery-guarantees/" rel="noopener noreferrer"&gt;Socket.IO delivery guarantees&lt;/a&gt; · &lt;a href="https://socket.io/docs/v4/connection-state-recovery/" rel="noopener noreferrer"&gt;Socket.IO connection state recovery&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use PostgreSQL for durable data such as account identities, match results, and chat history. Keep per-frame state in memory while you build the first working server. Assign each match a unique ID. Write the result and any related statistics in a transaction if they must succeed together, and protect the match ID with a unique constraint so retrying the finish operation cannot create a second result. Once that write succeeds, a history endpoint can return the result even after the socket disconnects. &lt;a href="https://www.postgresql.org/docs/current/tutorial-transactions.html" rel="noopener noreferrer"&gt;PostgreSQL transactions&lt;/a&gt; · &lt;a href="https://www.postgresql.org/docs/current/ddl-constraints.html" rel="noopener noreferrer"&gt;PostgreSQL constraints&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy and verify the complete path
&lt;/h2&gt;

&lt;p&gt;Package the frontend, backend, and database in a Compose setup with documented environment variables. Keep actual credentials outside Git. Test the deployed page over HTTPS so you can verify secure WebSocket traffic through the same route real users take. If you use a reverse proxy, check that the Socket.IO path, WebSocket upgrade handling, and timeouts match the app. A working API endpoint alone does not prove that the socket path is working. &lt;a href="https://docs.docker.com/reference/compose-file/services/" rel="noopener noreferrer"&gt;Docker Compose services&lt;/a&gt; · &lt;a href="https://socket.io/docs/v4/reverse-proxy/" rel="noopener noreferrer"&gt;Socket.IO reverse proxy guide&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build one arena and confirm that puck collisions, scoring, and movement bounds work in isolated tests.&lt;/li&gt;
&lt;li&gt;Connect two separate browsers. Confirm that they receive the same match ID, different sides, and the same final score.&lt;/li&gt;
&lt;li&gt;Click join twice, let readiness time out, and disconnect during a match. Check that each event leaves the queue and match in a consistent state.&lt;/li&gt;
&lt;li&gt;Reconnect a player and confirm that the new socket can resume from a snapshot. Finish a match twice in a test and verify that history contains one result.&lt;/li&gt;
&lt;li&gt;Repeat the flow through the deployed proxy with two clients on different devices. Use application logs and metrics to tell connection failures apart from matchmaking, simulation, or persistence failures.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once this path is stable, add the surrounding features one at a time. Chat needs its own rules for who can see and send messages. Friend lists and presence should agree on who is online. A practice opponent can use the same paddle-input interface as a human player. New arenas can change visual rendering while keeping the same protocol. These features are easier to add when the backend already has clear boundaries.&lt;/p&gt;

&lt;p&gt;The full &lt;a href="https://github.com/fttranscendenceorganization/ft_transcendence" rel="noopener noreferrer"&gt;NETPONG source&lt;/a&gt; gives readers a concrete example to trace from the root module to the gateway, service, database, and browser.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>javascript</category>
      <category>nestjs</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
