Diagnostic step 1
Immediately enforce strict request size limits: set Express json/bodyParser limit to a conservative size and configure your reverse proxy (nginx 'client_max_body_size') to the same limit to reject oversized requests early.
Generated Oct 3, 2026, 12:35:03 AM
Immediately enforce strict request size limits: set Express json/bodyParser limit to a conservative size and configure your reverse proxy (nginx 'client_max_body_size') to the same limit to reject oversized requests early.
Implement streaming parsing for large JSON payloads using libraries such as stream-json or JSONStream — these parse the input token by token without keeping the whole document in memory.
If input can be chunked, switch clients to send newline-delimited JSON (ndjson) or multipart uploads where each record is processed and persisted before reading the next; this greatly reduces memory pressure.
Use a worker process or dedicated ingestion service with its own memory limits to isolate the main web process; consider using worker threads or a separate microservice to process heavy imports and return status via a job queue.
Add monitoring and graceful shutdown: listen for 'uncaughtException' and 'unhandledRejection' to log errors, but prefer to crash and restart on unrecoverable OOM with proper alerts. Implement rate limits and authentication on the import endpoint to reduce abuse. If the problem persists after streaming implementation, gather heap snapshots and GC traces and escalate to platform/infra for deeper memory profiling.