<?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: U C H E N N A </title>
    <description>The latest articles on DEV Community by U C H E N N A  (@vix1209).</description>
    <link>https://dev.to/vix1209</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1181343%2F443721a8-312d-4dee-9029-ee92d5e27f35.jpeg</url>
      <title>DEV Community: U C H E N N A </title>
      <link>https://dev.to/vix1209</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vix1209"/>
    <language>en</language>
    <item>
      <title>The Architecture Decisions That Actually Mattered: Building a Production-Ready Multi-Service Backend</title>
      <dc:creator>U C H E N N A </dc:creator>
      <pubDate>Sun, 31 May 2026 23:26:21 +0000</pubDate>
      <link>https://dev.to/vix1209/the-architecture-decisions-that-actually-mattered-building-a-production-ready-multi-service-backend-4ekj</link>
      <guid>https://dev.to/vix1209/the-architecture-decisions-that-actually-mattered-building-a-production-ready-multi-service-backend-4ekj</guid>
      <description>&lt;h2&gt;
  
  
  What most system design articles skip is the part where you explain why the boring choice was the right one
&lt;/h2&gt;




&lt;p&gt;I built a platform that runs social media giveaway events, a gift card marketplace, and telecom gift vending — all in one system, all sharing the same PostgreSQL database and Redis instance, all running in production on infrastructure that costs €27 a month.&lt;/p&gt;

&lt;p&gt;This article is not about the product. It is about the seven architectural decisions I made while building the backend, why I made them, and what the actual capacity ceiling looks like before anything needs to change.&lt;/p&gt;

&lt;p&gt;The full architecture document (20 sections, every design decision documented) is linked at the end. This is the version you can read in ten minutes.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Three services, not ten — and not one
&lt;/h2&gt;

&lt;p&gt;The backend is a NestJS monorepo with three independently deployable applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Giveaway API&lt;/strong&gt; (port 5000) — events, participants, host wallet, auth, admin&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Giftcard API&lt;/strong&gt; (port 5002) — cards, merchants, escrow, redemptions, merchant wallet&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Job Processor&lt;/strong&gt; (port 5001 / 5003) — background work only, no HTTP surface&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is not a microservice architecture. It is a modular monolith with a deployment boundary.&lt;/p&gt;

&lt;p&gt;The question most engineers get wrong is treating "microservices" as the goal rather than as a tool. I had two bounded domains with genuinely different data ownership and access patterns. Splitting them gave me independent deployability and the ability to scale each service's connection pool separately. Splitting further — into separate auth services, notification services, payment services — would have added coordination overhead with no operational gain at this scale.&lt;/p&gt;

&lt;p&gt;The monorepo means all three apps share one build pipeline, one migration runner, one set of gRPC contract types, and one test suite. Changes to shared infrastructure (JWT guards, Redis config, payment client) deploy everywhere in one merge. You get the organisational clarity of separate services without the dependency management nightmare of separate repositories.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. gRPC between services, not HTTP
&lt;/h2&gt;

&lt;p&gt;The Giveaway API and Giftcard API call each other constantly. The Giveaway side calls Giftcard to allocate prize escrows, issue gift card instances, and refund expired holds. The Giftcard side calls Giveaway to validate winner PINs, credit wallet refunds, and log payment audit records.&lt;/p&gt;

&lt;p&gt;The standard answer is REST. I used gRPC instead, for three concrete reasons.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typed contracts enforced at compile time.&lt;/strong&gt; The request and response shapes live in &lt;code&gt;.proto&lt;/code&gt; files and are compiled into TypeScript interfaces that both the caller and handler must satisfy. If you rename a field in the Giftcard service's response, the Giveaway service fails to compile. With REST JSON, that failure happens in production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bidirectional calls without auth overhead.&lt;/strong&gt; Both services call each other, over an internal Docker network. gRPC over TCP with no auth headers, no CORS, no URL routing. Just a typed method call that the runtime handles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Every gRPC call is persisted through Bull, not just retried in memory.&lt;/strong&gt; This is the part most architectures get wrong. A custom Proxy (&lt;code&gt;createQueuedGrpcService&lt;/code&gt;) intercepts every gRPC method call before it reaches the wire. Instead of calling the stub directly, it enqueues a &lt;code&gt;GRPC_CALL&lt;/code&gt; Bull job — serialising the service name, method name, and request payload into Redis. The Job Processor picks up the job and executes the actual gRPC stub:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API calls giftcardService.allocateCards(payload)
    → Proxy intercepts the call
    → Enqueues GRPC_CALL job to Bull (persisted to Redis)
    → Awaits job.finished() with a deadline timeout
    → Job Processor picks up job, executes real gRPC stub
    → Result returned to the waiting caller
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The caller still receives the response synchronously — from the outside it behaves like a direct call. But the transport goes through Redis, which means the call survives an API process restart, and Bull's retry policy handles failures at the execution layer. If the Job Processor is temporarily down, the call sits durably in Redis until it comes back.&lt;/p&gt;

&lt;p&gt;On top of this, a circuit breaker sits at the proxy level — before any job is enqueued. After five consecutive failures, the circuit opens and the proxy immediately rejects calls without touching Redis or the network. This prevents a struggling downstream service from filling the Bull queue with jobs that will all fail.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Redis is doing four different jobs simultaneously
&lt;/h2&gt;

&lt;p&gt;This is the part of the architecture that surprises most engineers when they see it.&lt;/p&gt;

&lt;p&gt;The same single Redis instance handles all of the following, concurrently:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bull queue backend.&lt;/strong&gt; Six job queues — email, social verification, notifications, analytics, event processing, WebSocket — all backed by Redis lists and sorted sets. AOF persistence is enabled, so queued jobs survive a Redis restart.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Socket.IO pub/sub adapter.&lt;/strong&gt; The WebSocket gateway runs in a separate process from the API. When the Job Processor needs to emit &lt;code&gt;giveaway.winner&lt;/code&gt; to an event room, it publishes to a Redis channel. Every gateway instance subscribed to that channel propagates the event to connected clients. This is what makes horizontal scaling of the WebSocket layer possible without any code changes — add more gateways, they all share rooms via Redis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TTL-based application cache.&lt;/strong&gt; A &lt;code&gt;CacheService&lt;/code&gt; wraps Redis with a &lt;code&gt;getOrSet(key, factory, ttl)&lt;/code&gt; pattern. Merchant wallet balances, bank lists, admin analytics aggregates, service fee rates — all cached with appropriate TTLs and invalidated on write. If Redis is unavailable, the cache degrades gracefully to always calling the database rather than throwing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Atomic concurrency control.&lt;/strong&gt; The real-time winner selection algorithm uses a Lua script executed atomically inside Redis. During a live event, up to hundreds of participants may submit prize attempts simultaneously. The script increments a budget counter only if it is below the current time-slot threshold — preventing over-awarding regardless of concurrent load, without any application-level locking.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'GET'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;lim&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'SET'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;exp&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;exp&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'EXPIRE'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One Redis instance. Four distinct, production-critical responsibilities. No Kafka, no separate cache cluster, no dedicated counter service.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. The escrow state machine is where financial correctness lives
&lt;/h2&gt;

&lt;p&gt;Gift card prizes work as follows: a host allocates cards to a prize pool, funds are held in escrow, winners claim their card, and the merchant receives the net settlement when the card is physically redeemed at a branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RESERVED → SETTLED   (redeemed at branch POS)
    │
    └─→ RELEASED  (event cancelled / prize unassigned / expiry)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every state transition is irreversible. Every financial operation carries an idempotency key. The settlement calculation strips out the payment provider's deposit fee before applying the platform service rate — because the provider already took that fee at topup time, and charging a service fee on money the platform never held would be a systematic double-charge on merchants.&lt;/p&gt;

&lt;p&gt;The most important design decision here is the ordering of operations at settlement. Two payment transfers must happen: one to the merchant's payout account, one to the platform's fee account. If the database were committed first and then a transfer failed, a compensation transaction would be needed. Instead, both transfers run before any database write. A failure on either leg leaves the database untouched, and the client retries safely — both transfer references are idempotent, so a retry after a partial success is clean.&lt;/p&gt;

&lt;p&gt;Finalization, where prize escrows are first created via cross-service gRPC calls, uses an inline saga compensation pattern. If the wallet deduction fails after one or more escrows have been reserved, the catch block immediately refunds each escrow before re-throwing the error. &lt;code&gt;Promise.allSettled&lt;/code&gt; ensures a failed refund on one prize does not block the others.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. The job processor runs in two separate modes
&lt;/h2&gt;

&lt;p&gt;The job processor binary starts in one of three modes controlled by &lt;code&gt;JOB_MODE&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;JOB_MODE=worker&lt;/code&gt; — email sending, event draws, social API verification, analytics&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;JOB_MODE=gateway&lt;/code&gt; — Socket.IO WebSocket server only&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;JOB_MODE=all&lt;/code&gt; — both, for development&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These scale on completely different axes. Workers scale when the job queue backlog grows. Gateways scale when the number of concurrent WebSocket connections grows. A worker crash means queued jobs drain slower — the data is safe in Redis. A gateway crash means connected clients briefly disconnect and reconnect via Socket.IO's built-in reconnection. These are independent failure modes with no coupling.&lt;/p&gt;

&lt;p&gt;The API processes never touch Socket.IO directly. When the Giveaway API needs to broadcast a winner announcement to everyone in an event room, it enqueues a job. The gateway dequeues it and emits. This keeps the HTTP event loop free from the overhead of maintaining persistent connections.&lt;/p&gt;

&lt;p&gt;Scaling either process is one command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker compose up &lt;span class="nt"&gt;--scale&lt;/span&gt; worker-prod&lt;span class="o"&gt;=&lt;/span&gt;4 &lt;span class="nt"&gt;-d&lt;/span&gt;
docker compose up &lt;span class="nt"&gt;--scale&lt;/span&gt; gateway-prod&lt;span class="o"&gt;=&lt;/span&gt;3 &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bull distributes jobs across all worker instances automatically. The Redis adapter keeps Socket.IO rooms synchronised across all gateway instances automatically. No Kubernetes required.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Observability: infrastructure errors go to Sentry, not to users
&lt;/h2&gt;

&lt;p&gt;The observability design makes a deliberate distinction between two categories of errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User-facing errors&lt;/strong&gt; (validation failures, not-found, unauthorised) are returned as structured HTTP responses. The user sees a clear message. The application handles them with &lt;code&gt;ErrorInterceptor&lt;/code&gt; and &lt;code&gt;ErrorFilter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Infrastructure errors&lt;/strong&gt; (Nomba transfer failed, gRPC circuit open, Bull job exhausted retries, Redis connection dropped) are captured to Sentry in production and never propagate to the user as HTTP 500s with internal stack traces. These are engineering signals, not user messages.&lt;/p&gt;

&lt;p&gt;Every infrastructure boundary has an explicit Sentry capture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;OnQueueFailed&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;onFailed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;job&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isLastAttempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attemptsMade&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attempts&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isLastAttempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;Sentry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;withScope&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;queue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;QueueName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;EVENT_PROCESSING&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setExtra&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;correlationId&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;correlationId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;Sentry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;captureException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sentry capture is disabled in development and staging — development generates constant infrastructure noise (Redis not yet connected, gRPC services starting up) that would drown the production error stream.&lt;/p&gt;

&lt;p&gt;Every HTTP request carries an &lt;code&gt;x-correlation-id&lt;/code&gt; header that is propagated into every Bull job enqueued during that request. When a social verification job fails ninety seconds after the original HTTP request, the Sentry event includes the correlation ID — making it possible to trace the failure to the originating user action without a distributed tracing platform.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. The honest capacity ceiling
&lt;/h2&gt;

&lt;p&gt;With one VPS (8 vCPU, 16 GB RAM), one PostgreSQL VPS, and default TypeORM connection pools, this is what the system handles:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Capacity&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Concurrent browsing / dashboard reads&lt;/td&gt;
&lt;td&gt;300–500 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Simultaneous event registrations&lt;/td&gt;
&lt;td&gt;~100–200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Concurrent auth operations&lt;/td&gt;
&lt;td&gt;~50–100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Concurrent WebSocket connections&lt;/td&gt;
&lt;td&gt;5,000–10,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Total comfortable active users&lt;/td&gt;
&lt;td&gt;1,000–3,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Total registered users (10–20% active)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;15,000–30,000&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The first wall is the TypeORM connection pool, which defaults to 10 connections per app. Three apps × 10 = 30 connections total. Increasing this to 25 per app costs nothing and roughly triples concurrent write capacity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;extra&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;idleTimeoutMillis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The WebSocket ceiling is per gateway instance. Each additional gateway instance added via &lt;code&gt;--scale&lt;/code&gt; increases this linearly, because the Redis adapter keeps rooms synchronised.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. The scaling roadmap
&lt;/h2&gt;

&lt;p&gt;The architecture is designed so that each scaling action is independent and requires no code changes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 1 (now):&lt;/strong&gt; Single VPS, tune connection pools, run 1 gateway + 1 worker. Handles 15,000–30,000 registered users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 2:&lt;/strong&gt; Add more workers (&lt;code&gt;--scale worker-prod=3&lt;/code&gt;). Scales queue throughput. No infrastructure change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 3:&lt;/strong&gt; Move Redis to a dedicated VPS when adding a second app VPS. All instances point at the same Redis URL. Bull queues and Socket.IO rooms synchronise automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 4:&lt;/strong&gt; Add a second app VPS. Traefik load-balances across both. No code changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 5 (Kubernetes):&lt;/strong&gt; Only justified when managing 3+ VPS nodes manually becomes operationally expensive. The current Docker Compose setup maps nearly 1:1 to Kubernetes Deployments when that time comes — stateless containers, externalised config, health checks already defined.&lt;/p&gt;




&lt;p&gt;The full architecture document covers every decision documented here in depth, plus: the database schema separation design, the full gRPC contract structure, the presigned URL file upload pattern, the drift-corrected countdown timer implementation, the complete financial flow for every money movement in the system, and the detailed scaling migration procedures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read the full architecture document →&lt;/strong&gt; &lt;a href="https://blog.ucheofor.xyz/post/e02kg4" rel="noopener noreferrer"&gt;https://blog.ucheofor.xyz/post/e02kg4&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built with NestJS 11, TypeScript, PostgreSQL 15, Redis 7, gRPC, Bull, Socket.IO, Traefik, and Docker on Hetzner Cloud.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>backend</category>
      <category>systemdesign</category>
      <category>microservices</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
