Skip to main content
ABScaleForge
Back to blog
2 min read

WebSockets and Redis Queues — Async UI Without Blocking the API

Building an event gateway with Socket.IO and Redis so long-running reports and bulk jobs notify users in real time instead of timing out the browser.

Node.jsSocket.IORedisExpressTypeScriptEvent-Driven

Long tasks — report generation, AI calls, bulk notifications — should not block the main API or leave users staring at a spinner until timeout. We built the AI/ML Gateway to solve exactly that.

The user experience problem

A user clicks "Generate report." The backend needs 30–90 seconds. If the HTTP request stays open:

  • Load balancers may cut the connection
  • The user refreshes and triggers duplicate work
  • The main API thread pool fills with slow requests

The fix is enqueue and notify: accept the job immediately, process async, push a result when done.

Architecture

Browser → Main App → Gateway (enqueue) → Redis queue
                              ↓
                     Worker processes job
                              ↓
                     Socket.IO → Browser ("done")

The gateway is a Node.js Express service with:

  • Redis queues for durable job storage and retries
  • Socket.IO for room-based browser subscriptions
  • Sequelize where persisted job state is needed

The main app never blocks. It returns a job ID and the client listens for completion.

Design choices

  • Correlation IDs tie HTTP requests, queue jobs, and socket events together
  • Room per user/session so notifications do not leak across accounts
  • Idempotent job handlers so retries do not duplicate side effects
  • Graceful degradation — if sockets disconnect, clients can poll job status

When this pattern fits

Use async + push when:

  • Work routinely exceeds 5–10 seconds
  • Users need live progress (export 50%, 100%)
  • Multiple features share the same worker pool

Skip it when a simple 202 Accepted + email notification is enough, or when Server-Sent Events suffice for one-way streams.

Lesson

Event-driven UI is not about flashy tech — it is about respecting HTTP request lifetimes and keeping the core API fast. Redis + WebSockets is a proven combo for Laravel or FastAPI backends that should not run heavy work inline.