A scalable and high-performance user service built with NestJS, Prisma, and Redis-based versioned caching.
- 🔧 Clean architecture with Repository & Service layers
- ⚡ High-speed Redis caching with version control
- 🧪 Easy to test and extend
- 📦 Built with Prisma ORM and TypeScript
- 🛡️ Type-safe DTOs and clean code structure
Method | Endpoint | Description |
---|---|---|
GET | /users |
Get all users |
GET | /users/:id |
Get user by ID |
POST | /users |
Create a new user |
PUT | /users/:id |
Update existing user |
DELETE | /users/:id |
Delete user |
This service uses versioned Redis caching to ensure high performance and consistency, without manual cache invalidation.
- List cache key:
users-v:{version}
- Single user cache key:
user:{id}-v:{version}
GET /users
→ Reads fromusers-v:{version}
POST /users
→ Creates user, thenINCR users:version
PUT /users/:id
→ Updates user, bumpsusers:version
anduser:{id}:version
DELETE /users/:id
→ Deletes user, bumps versions
This ensures that any mutation (create/update/delete) results in a new cache version, without needing to delete keys.
Cached data is automatically set with an expiration time (e.g., 1 hour), keeping memory usage optimized.
# 1. Initial request - DB hit + cache set
GET /users
# 2. Create user - version incremented
POST /users
# 3. Request again - new version forces DB hit and new cache set
GET /users
# 4. Same logic applies for:
GET /users/:id
PUT /users/:id
DELETE /users/:id