-
Multiple DB Calls in several service methods (
findOne,remove, etc.). -
No caching layer, causing repeated DB hits for identical queries.
-
Unoptimized filtering — previously done in-memory, not at the DB level.
-
Improper error handling and inconsistent repository usage.
-
Inconsistent field naming (
due-datevsdueDate) causing DTO mismatches. -
JWT secret misconfiguration and environment variable inconsistency.
-
Missing transactional control for job queue integration.
-
Redis caching integration (for query-heavy endpoints like
findAll,getStats). -
QueryBuilder-based pagination & filtering (no in-memory filtering).
-
Transactional job enqueueing — queue jobs added after successful commit to avoid stale tasks.
-
Optimized repository pattern usage to reduce redundant queries.
-
Consistent DTO naming and schema alignment for
dueDate. -
JWT strategy cleanup — environment variable renamed to
JWT_SECRET. -
Centralized error handling using NestJS
NotFoundExceptionandInternalServerErrorException.
-
Added Redis caching (via
@nestjs/cache-manager) to minimize DB load. -
Cache invalidation handled automatically after create/update/delete operations.
-
Background job retries with exponential backoff using BullMQ.
-
All DB operations wrapped in TypeORM transactions for data integrity.
-
JWT secret stored securely via environment variable (
JWT_SECRET). -
Removed duplicate DB queries and replaced with optimized QueryBuilder operations.
| Decision | Rationale |
|---|---|
| Redis caching | Reduces DB calls for read-heavy endpoints. |
| QueryBuilder for filtering | Enables efficient DB-level filtering & pagination. |
| Transactions + BullMQ | Ensures data consistency before job enqueue. |
| Consistent DTO schema | Prevents mismatches between code & DB schema. |
| Centralized logging | Helps trace background job or DB failures. |
-
Slight overhead for maintaining cache invalidation logic.
-
Redis adds infrastructure complexity but provides significant performance gain.
-
Transactions may introduce minimal latency, but ensure data consistency.
| File | Description |
|---|---|
src/modules/tasks/tasks.service.ts |
Major refactor — added Redis cache, optimized DB calls, transactional queue integration. |
src/modules/tasks/dto/task-filter.dto.ts |
Added pagination & filtering support. |
src/modules/tasks/dto/create-task.dto.ts |
Fixed naming conflict (dueDate field). |
src/modules/tasks/tasks.controller.ts |
Updated endpoints to align with new service structure. |
src/modules/tasks/task-processor.service.ts |
Handles background jobs with retry/backoff. |
src/modules/schedule-tasks/schedule-tasks.module.ts |
Imported TypeOrmModule & registered Task entity. |
src/auth/jwt.strategy.ts |
Changed env variable to JWT_SECRET. |
-
After every new service or module creation, register it in its corresponding controller.
-
Maintain consistent DTO validation and naming across all modules.
-
Verify Redis caching using
redis-cli monitoror by addingconsole.logfor cache hits/misses.