简体   繁体   中英

Rest API Design in case of partial failure

So I have a ticket booking system.

I have ticket booking request on API, from my application we call payment service.

If failed on the first attempt we proceed by adding the message on the queue for handling payment later. And proceed with issuing the ticket to the customer.

From queue, we retry payment with payment API 10 times in 10 minutes if no success we add some status to that ticket booking record and by offline mean get money from the customer.

Problem : We are getting many such booking due frauds.

Solution :

I have a solution in mind, I will not proceed with issuing a ticket in payment fail, instead, I want to return something different HTTP code to the client. like everything else except payment is the success.

And while processing the message from the queue if it fails after 10 attempts I want to inform client this transaction is failed.

If pass let the client know to proceed with issuing the ticket

Question : Does this solution have technical feasibility?

I will not proceed with issuing a ticket in payment fail, instead, I want to return something different HTTP code to the client. like everything else except payment is the success.

I would return 202 in case the payment is added to the queue.

202 Accepted: The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place. There is no facility for re-sending a status code from an asynchronous operation such as this.

Otherwise, a 200 or 201 if it was successful.

And while processing the message from the queue if it fails after 10 attempts I want to inform client this transaction is failed.

A common notification mechanism is delivering a message via HTTP on some client specified endpoint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM