Recommendation Service ๐ค
The Recommendation Service is responsible for generating personalized product recommendations for users in ShopVerse based on their interaction history.
It is a purely event-driven, read-optimized service that improves user engagement without affecting core transactional workflows.
๐ฏ Responsibilitiesโ
The Recommendation Service handles:
- Consuming user interaction events from Kafka
- Storing interaction history
- Computing recommendation scores
- Generating personalized product recommendations
- Exposing recommendation APIs to clients
๐ง Why a Separate Recommendation Service?โ
Recommendations are:
- Data-driven
- Continuously evolving
- Computationally intensive
Separating them ensures:
- No impact on order or payment flows
- Independent experimentation with algorithms
- Easy evolution from rule-based โ ML-based models
- Independent scaling
๐๏ธ High-Level Architectureโ
๐ก Event Consumption Modelโ
The Recommendation Service does not receive direct API calls from other services. It reacts only to Kafka events.
Events Consumed:โ
VIEW_PRODUCTADD_TO_CARTORDER_PLACED
๐ Interaction Processing Flowโ
๐๏ธ Data Modelโ
UserInteraction Documentโ
iduserEmailproductIdeventType(VIEW, CART, ORDER)timestamp
Recommendation Documentโ
iduserEmailproductIdscoresource(PERSONAL / POPULAR)createdAt
MongoDB is used for:
- Flexible schema
- High write throughput
- Fast aggregation queries
๐งฎ Recommendation Scoring Strategyโ
ShopVerse uses a weighted interaction-based scoring model.
| Interaction | Weight |
|---|---|
| VIEW_PRODUCT | +1 |
| ADD_TO_CART | +3 |
| ORDER_PLACED | +5 |
Scoring Logic:โ
- Scores accumulate per user-product pair
- Recent interactions weigh more
- Products with highest scores are recommended
This approach is:
- Simple
- Explainable
- Easily extendable to ML models
๐ง Recommendation Typesโ
1๏ธโฃ Personalized Recommendationsโ
- Based on userโs own interactions
- Returned when sufficient data exists
2๏ธโฃ Popular Recommendationsโ
- Based on global interaction frequency
- Used for new or inactive users
๐ APIsโ
Recommendation APIโ
| Method | Endpoint | Role | Description |
|---|---|---|---|
| GET | /api/recommendations | CUSTOMER | Get recommended products |
Example Response:
[
{
"productId": "PROD123",
"score": 12.5,
"source": "PERSONAL"
}
]
๐ Security Modelโ
-
Accessed via API Gateway
-
Identity propagated using:
X-User-EmailX-User-Role
-
Only authenticated customers can fetch recommendations
-
Admin access is restricted
๐ก๏ธ Reliability & Idempotencyโ
- Kafka events may be delivered multiple times
- Each interaction is uniquely identified
- Duplicate interactions are safely ignored
- Consumers commit offsets only after successful processing
โ ๏ธ Failure Scenariosโ
โ Kafka Lagโ
- Recommendations delayed
- Core services unaffected
โ MongoDB Downโ
- Interactions retried
- No data loss due to Kafka retention
โ No Interaction Dataโ
- Fallback to popular recommendations
โ๏ธ Key Componentsโ
UserInteractionConsumerโ Kafka consumerRecommendationServiceโ Scoring & aggregation logicUserInteractionRepositoryโ MongoDB persistenceRecommendationRepositoryโ Recommendation storageRecommendationControllerโ REST APIGatewayHeaderAuthenticationFilterโ SecurityGlobalExceptionHandlerโ Error handling
๐ Scalability Considerationsโ
- Stateless service
- Kafka partitions enable parallel consumption
- MongoDB supports horizontal scaling
- Recommendation APIs are read-optimized
๐งช Testing Strategyโ
- Unit tests for scoring logic
- Kafka consumer tests
- MongoDB aggregation tests
- Security tests for role enforcement
๐ Future Enhancementsโ
- Collaborative filtering
- ML-based recommendations
- Time-decay scoring
- Category-based suggestions
- A/B testing of algorithms
The current design supports easy evolution without architectural changes.
๐ Summaryโ
The Recommendation Service provides:
- Personalized user experience
- Event-driven scalability
- Clean separation from core workflows
- Extendable recommendation logic
It transforms user behavior into intelligent product discovery, completing the ShopVerse ecosystem.