A high-performance .NET Web API for managing orders, featuring Redis Caching to optimize data retrieval and reduce database load. This project implements the Cache-Aside Pattern to ensure data consistency and high availability.
- Full CRUD Operations: Create, Read, Update, and Delete orders.
- Redis Caching:
- Implements Cache-Aside Pattern.
- Optimized response time (reduced from ~3.5s to ~12ms).
- Handles cache invalidation on Create, Update, and Delete operations.
- Architecture:
- Service Layer Pattern: Decouples business logic from controllers.
- DTO Pattern: Separates domain entities from API contracts.
- Robust Validation: Uses FluentValidation to ensure data integrity.
- Mapping: Uses AutoMapper for clean object-to-object mapping.
- Global Error Handling: Centralized middleware for managing exceptions.
- Database: SQL Server with EF Core (Code-First approach & Data Seeding).
- Framework: .NET 9 Web API
- Database: SQL Server (Entity Framework Core)
- Caching: Redis (StackExchange.Redis)
- Object Mapping: AutoMapper
- Validation: FluentValidation
- Documentation: Swagger
Follow these steps to get the project running locally.
- .NET 9 SDK installed.
- SQL Server (LocalDB or Docker).
- Redis Server running on
localhost:6379.- Windows: Use Memurai or Docker (
docker run -p 6379:6379 -d redis).
- Windows: Use Memurai or Docker (
-
Clone the repository:
git clone [https://github.com/MahmoodElbadri/AnyWareTask.git](https://github.com/MahmoodElbadri/AnyWareTask.git) cd AnyWareTask -
Configure Database: Check
appsettings.jsonand update theDefaultConnectionstring if necessary. The project uses(localdb)\\mssqllocaldbby default. -
Apply Migrations & Seed Data: Open the Package Manager Console in Visual Studio and run:
Update-DatabaseThis will create the database and seed it with initial test data.
-
Run the Application: Press
F5in Visual Studio or run:dotnet run
-
Explore the API: Navigate to
https://localhost:7xxx/swaggerto test the endpoints via Swagger UI.
- First Request (Cache Miss):
- Call
GET /api/orders/{id}. - The application fetches from SQL DB and saves to Redis.
- Response time: ~Normal DB latency.
- Call
- Subsequent Requests (Cache Hit):
- Call the same endpoint again.
- The application fetches instantly from Redis.
- Response time: ~Ultra-low latency (<20ms).
- Cache Invalidation:
- Call
PUTorDELETEon that order. - The system automatically removes the stale data from Redis.
- The next
GETrequest will fetch fresh data from the DB.
- Call
Developed by Mahmood Elbadri as part of a Technical Assessment.