Katkat

Design a basic credit card system

AmazonSoftware Engineer · Technical Screen

Last updated

This problem tests object-oriented modeling and state management by requiring the design of a class structure that handles credit limits, transaction authorization, and balance tracking.

Problem Statement

Design a simplified Credit Card processing system that models a user's credit account. Your system should be able to track a credit limit, the current balance, and a history of transactions.

Requirements

  1. CreditCard: Should store cardholder information, the credit limit, and the current outstanding balance.
  2. Transaction: Should store an amount, a timestamp, and the status (PENDING, APPROVED, DECLINED).
  3. ProcessTransaction(amount): A method to attempt a transaction. A transaction should be declined if the amount exceeds the remaining credit (limit - current balance).
  4. GetStatement(): Should return a list of all successful transactions for the current billing cycle.

Constraints

  • The balance cannot exceed the credit limit.
  • Ensure thread safety if multiple transactions occur simultaneously (conceptual).
  • Maintain a clean separation between the user account state and the transaction logs.

Example

# Input:
card = CreditCard(limit=1000)
card.process_transaction(500) # Returns True
card.process_transaction(600) # Returns False (exceeds limit)

# Output:
# card.get_balance() -> 500
# card.get_statement() -> [Transaction(500, Approved)]

Edge Cases

  • Transaction amount is zero or negative.
  • A transaction exactly equal to the remaining credit limit.
  • Concurrent attempts to exceed the credit limit.

Hints

Hint 1

Use a composition pattern where the CreditCard class maintains a list of Transaction objects to separate entity responsibilities.

Hint 2

Consider using an enum or a constants class for transaction statuses to improve readability and maintainability.

Hint 3

Think about using a mutex or a synchronized block if you need to ensure the balance calculation is atomic.

Follow-up questions

  • How would you modify your design to support daily transaction limits in addition to the total credit limit?
  • If this system needs to scale to millions of users, how would you handle database sharding for these transaction records?
  • How would you implement a 'Refund' operation that updates the balance and adds a new transaction entry?