How to make sending invoices to an external system more reliable? So that when the payment service is unavailable, the client can still reserve a seat and pay later (within 10 minutes).
sobes.tech AI
Answer from AI
To improve the reliability of sending invoices to an external payment system and to enable booking with subsequent payment within 10 minutes, the following approach can be implemented:
-
Asynchronous message queue. Instead of directly synchronously sending the invoice to the payment service, store the booking and invoice information in a local database and place the sending task in a queue (for example, using RabbitMQ, Kafka, or built-in queues).
-
Retry attempts. A background process (worker) will attempt to send the invoice to the external system with retries and exponential backoff until it receives confirmation of successful processing or the timeout (10 minutes) expires.
-
Local booking. The client is immediately confirmed of the reservation, even if the payment service is temporarily unavailable.
-
Cancellation or confirmation of booking. If the invoice cannot be sent and paid within 10 minutes, the booking is automatically canceled or moved to a pending status.
-
Idempotency. It is important that the invoice sending is idempotent — repeated requests do not create duplicates.
Example scheme:
- The client makes a booking request.
- The server saves the booking and places a task in the queue.
- The worker attempts to send the invoice.
- On success, it updates the booking status.
- On failure, it retries within 10 minutes.
- If it fails, it notifies the client or cancels the booking.
This approach increases reliability and improves user experience by not blocking the booking due to temporary issues with the payment service.