0
0
LLDsystem_design~12 mins

Payment strategy pattern in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Payment strategy pattern

This system handles payments using different payment methods like credit cards, PayPal, and bank transfers. It allows users to choose their preferred payment method, and the system processes the payment accordingly. The key requirement is to support multiple payment options without changing the core payment processing logic.

Architecture Diagram
User
  |
  v
Payment Controller
  |
  v
+-------------------+
| Payment Strategy   |
|  +-------------+  |
|  | CreditCard  |  |
|  | PayPal      |  |
|  | BankTransfer|  |
+-------------------+
          |
          v
   Payment Processor
          |
          v
      Payment Gateway
          |
          v
      Bank/Payment Network
Components
User
actor
Initiates payment requests selecting a payment method
Payment Controller
service
Receives payment requests and delegates to the appropriate payment strategy
Payment Strategy
pattern
Defines interface for different payment methods
CreditCard Strategy
service
Processes payments via credit card
PayPal Strategy
service
Processes payments via PayPal
BankTransfer Strategy
service
Processes payments via bank transfer
Payment Processor
service
Handles communication with external payment gateways
Payment Gateway
external_service
Third-party service that processes payment transactions
Bank/Payment Network
external_service
Final destination for payment settlement
Request Flow - 9 Hops
UserPayment Controller
Payment ControllerPayment Strategy
Payment StrategyPayment Processor
Payment ProcessorPayment Gateway
Payment GatewayBank/Payment Network
Bank/Payment NetworkPayment Gateway
Payment GatewayPayment Processor
Payment ProcessorPayment Controller
Payment ControllerUser
Failure Scenario
Component Fails:Payment Gateway
Impact:Payment transactions cannot be authorized or settled, causing payment failures
Mitigation:System retries requests, falls back to alternative gateways if available, or informs user to try later
Architecture Quiz - 3 Questions
Test your understanding
Which component decides which payment method to use?
APayment Gateway
BPayment Processor
CPayment Controller
DBank/Payment Network
Design Principle
This design uses the Strategy pattern to separate payment methods, allowing easy addition of new payment options without changing core logic. It also cleanly separates concerns between user interaction, payment processing, and external payment services.