Ecommerce with Loyalty Program
Design a gamified loyalty service for an e-commerce platform — levels, points, redemption limits, and a personalized discount engine.
Design a service that adds gamification elements to an e-commerce platform. This service tracks user transactions, letting users purchase products, redeem existing points during purchases (with constraints based on their level), and earn new points from those purchases. The service should incentivize purchases and engagement using points and levels, and be designed to stay flexible and extensible.
This one tests whether you can model layered business rules cleanly — levels that gate redemption limits, points that compound purchase-over-purchase, and a discount engine that stacks on top of both — without the logic turning into a pile of conditionals.
Objective
The primary objective of this project is to design and implement an in-memory loyalty service where users earn and redeem points based on their level, automatically progress between levels as points accumulate, and — as a bonus — receive a personalized discount based on purchase history.
Functional Requirements
Requirements are split into two tiers so you know what to prioritize under time pressure: build first, and build only after the core is demoable.
Part 1 — Basic Requirements
Core functionality you must build and get working first.
1. Onboard User
Onboard a user to the platform with onboard <user_name>.
2. User Points
Users earn points for every purchase, calculated from their level and the purchase amount, and can view their current point balance at any time.
3. User Levels
Users progress through levels automatically as points accumulate. Each level has its own benefits — redemption limits and point-earning rate.
4. Purchase Products with Points Redemption
Users can redeem existing points for a portion of a purchase, choosing any amount up to what they're eligible for. They also earn points on the remaining amount paid with real money, based on their level's ₹100-to-points rate. Command shape: purchase <user_name> <order_amount> <points_to_redeem>.
5. Get User's Stats
Users can view their current level and point balance via getUserStats <user_name>.
Part 2 — Bonus Feature
Extensibility check — can your design layer a discount engine on top of the existing points and level logic without disturbing it.
Personalized Discount
The discount is applied after any points redemption, and is capped at ₹5000. Once a discount is used, eligibility resets — the user again needs at least 3 orders or ₹10,000 in spend to qualify.
Example Usage: Sample Test Walkthrough
Here's a sequence of purchases for user1 that exercises point earning, level progression, redemption, and the bonus discount.
1. Bronze purchase
Input: purchase user1 800.00 0
Output: Purchase successful. Points added: 80. Total payable amount: 800.00.
Current points: 80. Current level: Bronze
Orders count: 1
2. Bronze purchase — insufficient points to redeem
Input: purchase user1 4200.00 100
Output: Purchase Failed. Not enough points to redeem
3. Bronze purchase — crosses into Silver
Input: purchase user1 4200.00 0
Output: Purchase successful. Points added: 420. Total payable amount: 4200.00.
Current points: 500. Current level: Silver
Orders count: 2
4. Silver purchase with redemption
Input: purchase user1 3000.00 300
Output: Purchase successful. Points redeemed: 300. Points added: 337.5.
Total payable amount: 2700.00. Current points: 537.5. Current level: Silver
Orders count: 3
5. Silver purchase — crosses into Gold
Input: purchase user1 5000.00 0
Output: Purchase successful. Points added: 625.0. Total payable amount: 5000.00.
Current points: 1162.5. Current level: Gold
Orders count: 4
6. Gold purchase with redemption and discount (bonus)
Assume user1 now qualifies for a 5% discount (orders > 3).
Input: purchase user1 12000.00 800
Output: Purchase successful. Points redeemed: 800. Points added: 1596.0.
Discount applied: ₹560.0. Total payable amount: 10640.0.
Current points: 1958.5. Current level: Gold
Orders count: 5
7. Check final stats
Input: getUserStats user1
Output: user1 has 1958.5 points. Current level: Gold.
user1 progresses from Bronze to Gold purely through accumulated points, a mid-level redemption is correctly capped and validated, and the bonus discount is applied after redemption and before the final points calculation — landing at 1958.5 points and Gold level.
Guidelines
You have 90 minutes. Use only in-memory data structures — no external databases like MySQL. No UI is required; a simple driver program or test cases are enough to demo the code, but don't over-invest in input parsing. The use of Gen AI or any other code-generation tool is prohibited. Focus on the bonus feature only after the required features are complete and demoable.