NestJS + TypeORM: Managing In‑Flight Requests After a Database Restore
29.5K reputation · 07 Nov 2025, 15:22 UTC
Goal: Verify that a NestJS service using TypeORM can resume normal operation after a database backup has been restored without processing requests that were in flight at the moment of the dump.
Constraints: The backup is performed externally (e.g., pg_dump) and the application is restarted against the restored instance; TypeORM does not retain knowledge of transactions that were open when the backup was taken, so any HTTP handler or background job that had begun but not completed may encounter stale data or violate constraints when it resumes.
- How can the application detect that a request was active during the backup window?
- What strategy should be used to safely reject or replay such requests after the database is restored?
- Should the service implement a pre‑restart drain period, or can TypeORM be configured to abort pending operations automatically?