---
issue: 070
title: "Backend: notifyAllSellersAboutNewRequest unbounded fan-out — N DB writes + N socket emits per new request"
severity: high
domain: Marketplace
labels: [performance, backend, scalability]
status: open
created: 2026-05-30
source: Full Codebase Audit 2026-05-30
---

# Backend: notifyAllSellersAboutNewRequest unbounded fan-out — N DB writes + N socket emits per new request

**Severity:** high
**Domain:** Marketplace
**Labels:** performance, backend, scalability

## Description

`PurchaseRequestService.ts:196` loops over every seller and issues one `Notification.insertOne` and one `socket.emit` per seller, wrapped in `setTimeout`. With hundreds of sellers this creates hundreds of sequential DB writes and socket emits, blocking the event loop and risking OOM.

## Options

1. Batch with `insertMany` for notifications and a single room/broadcast emit instead of per-seller `setTimeout`.
2. Move to a queue/worker that processes seller notifications asynchronously with concurrency limits.
3. Fan out via a topic/room subscription rather than per-seller writes.

## Recommendation

Use `insertMany` + a single broadcast/room emit, or offload to a queue with bounded concurrency. This is an architectural change.

## Affected Files

- `backend/src/services/marketplace/PurchaseRequestService.ts:196`

## References

- [Full Codebase Audit 2026-05-30](../09%20-%20Audits/Full%20Codebase%20Audit%20-%202026-05-30.md) — DEC-40
