š° E-commerce has grown rapidly, requiring reliable and scalable payment systems.
š³ Payment systems involve multiple parties, including payment gateways, acquiring banks, and customer banks.
š There are two common ways to build a payment system: using a payment service provider (PSP) or connecting directly to banks.
š³ The payment system doesn't store card data and relies on a payment service provider (PSP) for processing transactions.
š Transaction failures and inconsistencies require reconciliation in the system.
š Building a reliable payment system requires considering technical concepts and handling large throughput of payment requests.
š The core features of an online store payment system include generating payment events, storing payment details, and coordinating with a PSP for card processing.
š¦ The payment service updates the merchant's wallet and ledger to track account balances and financial transactions.
š Communication between internal and external services can be synchronous or asynchronous.
š” The design of a payment system needs to account for potential failures and communication issues.
š” Synchronous communication is not suitable for most cases and asynchronous communication is preferred.
š” Asynchronous communication, using persistent queues like Kafka, helps handle uneven traffic and prevents service overload.
š” Implementing a reliable payment system involves addressing system failures, poison pill errors, and functional bugs.
š” Using messaging queues like Apache Kafka can ensure transaction completion and mitigate the challenges of a payment system.
š” Kafka is used to persist communication messages and ensure their delivery to other services.
š Retry strategies are important for handling network issues and ensuring successful payment requests.
ā° Timeouts are implemented to avoid indefinite waiting for a response.
š When an order fails, it is important to determine the status of the payment and communicate it to the customer to avoid confusion.
š” Timeouts should be set high enough to allow slower responses but also low enough to avoid waiting indefinitely.
š« Fallback mechanisms can be implemented to handle failures in dependent services and ensure uninterrupted payment processing.
š„ Incompatible messages, known as poison pill errors, can be saved for later debugging or discarded using a dead letter queue.
ā³ In cases where a service is down, failed transactions can be stored in a persistent queue and processed once the service recovers.
ā»ļø Hidden potency can be utilized to safely retry payment operations without charging the customer twice.
š³ To avoid double payments in a payment system, a unique key called a hidden potent key is used.
š Hidden potent keys, often generated as UUIDs, are added to the HTTP header and serve as the ID of the payment order.
š In a distributed payment system, data replication and workload distribution improve reliability and scalability.
š Encryption is crucial to protect data at rest and during transmission in a payment system.
š TLS and HTTPS can protect data transmitted over a network.
š Access control and two-factor authentication verify user identity and restrict data access.
š¾ Regularly updating software and backing up data helps prevent vulnerability exploitation and data loss.
š Using long and complex passwords can enhance security against password cracking.
š Monitoring data integrity allows detection of changes and malware.
ā Reliability and fault tolerance are important for a payment system.