Gift Card Design

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-05-29

Problem Statement

Design the core low-level design (LLD) of a Gift Card system that allows users to create, activate, redeem, and manage gift cards.

The system should handle balance tracking, expiry validation, and transaction logging.


🧠 Functional Requirements

Create Gift Card

•Admin or system can issue a new gift card.
•Each card has a unique identifier, initial balance, issue date, and expiry date.


Activate / Deactivate Gift Card

•Cards can be activated (usable) or deactivated (e.g., blocked, expired, or used up).


Check Balance

•Given a card ID, return the available balance.


Redeem Gift Card

•Deduct an amount from the balance when the card is used.
•Reject redemption if:
•Insufficient balance
•Card expired or inactive


Reload / Top-up Gift Card (Optional)

•Allow adding more funds to an existing active card (depending on business rules).


Expiry Handling

•Cards expire after a set period (e.g., 12 months from issue date).
•Expired cards cannot be redeemed.

Transaction History

•Maintain a record of all redemptions, reloads, and balance checks.


🚫 Non-Functional Requirements


•Thread-safe operations for balance updates.
•Accurate transaction logs for auditability.
•Scalable in-memory structure for simulation (DB not required for LLD).
•Extensible design to support different card types (physical, eGift, promo code, etc.).


🧱 Suggested Classes


ClassResponsibility


GiftCard


Represents a single gift card with ID, balance, status, and expiry date.


GiftCardManager


Manages card creation, lookup, redemption, reload, and balance queries.


Transaction


Represents a single operation (redeem/reload/check) with timestamp and amount.


CardStatus (Enum)


Enum with values like ACTIVE, INACTIVE, EXPIRED, BLOCKED.


TransactionType (Enum)


Enum with values like REDEEM, RELOAD, CHECK_BALANCE.


GiftCardStore


In-memory repository or map of all cards (e.g., Map<String, GiftCard>).


🔄 Example Flow


1.Create Card
1 2card = GiftCardManager.createCard(1000, expiry=2026-12-31)

Output:

1 2Gift Card created: ID=GC1234, Balance=1000, Status=ACTIVE

2. Redeem

1 2GiftCardManager.redeem("GC1234", 200)

Output:

1 2Redeemed ₹200. Remaining balance: ₹800


3.Check Balance

1 2GiftCardManager.getBalance("GC1234")

Output:

1 2Balance: ₹800


4.Expiry Handling


•If current date > expiry date → status = EXPIRED.


🧪 Example Input / Output


Input:

1 2createCard(500) 3redeem("GC001", 200) 4redeem("GC001", 400)


Output:

1 2Gift Card GC001 created with ₹500 3Redeemed ₹200 → Remaining balance ₹300 4Redemption failed: Insufficient balance


⚙️ Constraints


•Gift card count ≤ 10^5
•Balance precision: 2 decimal places
•Expiry check: daily or per transaction
•Redeem concurrency: ensure atomic updates


🎯 Goals


Your LLD should:


•Clearly define class structure, responsibilities, and relationships.
•Ensure data consistency (atomic redemption).
•Support future extensions like:
•Integration with payment gateways
•Gift card pooling or sharing
•Promotional / category-specific cards


✅ In short:


Design a modular, object-oriented Gift Card system that can create, activate, redeem, and track gift cards while ensuring accurate balance and expiry management.

Solution

Comments