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.

Ahsan Bilal
Principal Software Engineer
On this page
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.
See it in production
The product behind this article
Keep reading
All articles →Hiring a Remote Laravel, Node.js or Python Team in Pakistan: A Buyer's Guide
What to check before hiring an offshore development team in Pakistan: engagement models, time-zone overlap, code ownership and contracts, communication, technical vetting and red flags — with a checklist for your first call.
Production Node.js on Kubernetes — Lessons from Cluster Node
Building a portfolio-grade Node.js e-commerce API with JWT auth, idempotency, circuit breakers, OpenAPI docs, and real Docker/Kubernetes/Terraform deployment.
React Native vs. Flutter vs. Native: Which Should You Use for a Business App?
For most business apps, a cross-platform framework ships iOS and Android from one codebase at lower cost. Choose React Native if your team knows React or TypeScript, Flutter for pixel-identical custom UI, and native Swift/Kotlin for heavy device or performance work.