When your NestJS API depends on an AI service that can be slow or down, every request that waits on it makes the whole API feel broken. In FaceMark, a student attendance system, the NestJS API calls a separate FastAPI service that runs DeepFace/TensorFlow for face recognition. That service is the weakest link, so I put a circuit breaker between the two.
Face recognition takes time and sometimes fails. Without protection, a stuck AI service ties up requests in the NestJS API until timeouts pile up, and users see errors on endpoints that have nothing to do with faces.
A small circuit breaker class with three states:
The NestJS side wraps the AI call in this breaker, so login, courses and the rest of the API keep working while the AI service recovers.
If your product depends on an AI model or a third-party API, decide up front what the user sees when it is down. A breaker plus a clear error message is a small amount of code and saves you from cascading failures.
The code is public: [https://github.com/ZiadtahaM/FaceMark](https://github.com/ZiadtahaM/FaceMark) (NestJS 10, JWT auth, Swagger docs, rate limiting, automated tests).
I am a junior-plus full-stack developer (about 2 years Angular, 1 year NestJS) in Alexandria, Egypt, available for NestJS/TypeScript API work at $20-25/hour or a fixed price for a small scope. Message me on LinkedIn: [https://www.linkedin.com/in/ziad-taha-dev](https://www.linkedin.com/in/ziad-taha-dev)
Drafted with AI assistance, reviewed against the repository.