Affected Apps / Packages
Server (apps/server), Infrastructure / Other
Is your feature request related to a problem?
Yes. The backend Express application runs on a single Node.js thread by default. This does not utilize multi-core host machines in staging/production environments (e.g. AWS, Render, Docker). A single-threaded setup experiences request queuing and high latency under concurrent load, and presents a single point of failure if a request causes an unhandled exception that crashes the process.
Describe the solution you'd like
We want to introduce clustering using throng to spawn a pool of Node.js worker processes that share the same port and handle incoming requests concurrently.
-
Master / Worker Topology:
- Use
throng in the server entry point index.ts.
- The master process will read
CLUSTERING_ENABLED and WEB_CONCURRENCY (worker count) configurations and boot the workers.
- Each worker process will initialize its own database/Redis connections and start an instance of the Express server.
-
Cron & Background Job Isolation:
- Background sync and maintenance cron jobs (e.g.
githubSyncJob, viewsFlushJob) must only run on Worker 1 to avoid duplicate execution, race conditions, and excessive database locks.
-
Graceful Shutdown:
- Implement process signal handlers (
SIGTERM, SIGINT) in both the master and worker processes to perform a graceful teardown:
- Stop the HTTP server from accepting new connections.
- Complete in-flight requests with a reasonable timeout.
- Disconnect from Redis and Prisma cleanly.
Describe alternatives you've considered
- Running multiple container instances: While container orchestration (e.g., ECS, Kubernetes) handles scaling well, application-level clustering inside each container optimizes cost and CPU utilization.
- Using PM2: PM2 is heavy and requires separate process monitors, whereas programmatic clustering with
throng fits seamlessly inside a standard Node/TypeScript entry point.
Additional Context
- This setup will require adding
CLUSTERING_ENABLED and WEB_CONCURRENCY configurations in config.ts and the .env configuration files.
Affected Apps / Packages
Server (apps/server), Infrastructure / Other
Is your feature request related to a problem?
Yes. The backend Express application runs on a single Node.js thread by default. This does not utilize multi-core host machines in staging/production environments (e.g. AWS, Render, Docker). A single-threaded setup experiences request queuing and high latency under concurrent load, and presents a single point of failure if a request causes an unhandled exception that crashes the process.
Describe the solution you'd like
We want to introduce clustering using
throngto spawn a pool of Node.js worker processes that share the same port and handle incoming requests concurrently.Master / Worker Topology:
throngin the server entry point index.ts.CLUSTERING_ENABLEDandWEB_CONCURRENCY(worker count) configurations and boot the workers.Cron & Background Job Isolation:
githubSyncJob,viewsFlushJob) must only run on Worker 1 to avoid duplicate execution, race conditions, and excessive database locks.Graceful Shutdown:
SIGTERM,SIGINT) in both the master and worker processes to perform a graceful teardown:Describe alternatives you've considered
throngfits seamlessly inside a standard Node/TypeScript entry point.Additional Context
CLUSTERING_ENABLEDandWEB_CONCURRENCYconfigurations in config.ts and the.envconfiguration files.