Use:
- GET /health
Expected:
- status: healthy
- checks.database.status: ok
- checks.redis.status: ok
- checks.queue.status: ok
If unhealthy:
- Read the failing check message.
- Verify dependency availability.
- Confirm queue activity and backlog.
Core metrics:
- documents_generated_total
- batch_processing_duration_seconds
- queue_size
Recommended alerts:
- queue_size{state="pending"} high for more than N minutes.
- Failure ratio rising:
- rate(documents_generated_total{status="failed"}[5m])
- batch_processing_duration_seconds p95 above SLA.
Structured logs include correlation fields when available:
- batchId
- documentId
- userId
- jobId
Use these fields to trace a single document from enqueue to completion/failure.
- API endpoints return 503 for document operations.
- Worker retries Mongo operations with exponential backoff.
- enqueue falls back to an in-memory queue.
- a background drain attempts to push fallback jobs when Redis recovers.
- monitor fallback size from /health checks.queue.fallback.
- PDF generation has a strict timeout (PDF_TIMEOUT_MS, default 5000ms).
- timed-out tasks are failed and retried by queue policy.
Signals handled:
- SIGTERM
- SIGINT
Shutdown order:
- stop accepting new HTTP connections
- close worker gracefully
- close queue client
- close MongoDB
- close Redis cache client
Rebuild:
- pnpm run build
Run in watch mode:
- pnpm run watch
Run benchmark:
- pnpm run benchmark
- Confirm /health is healthy.
- Confirm queue_size pending is decreasing.
- Verify recent logs for repeated errors.
- Validate one end-to-end batch manually.