开发者

How to achieve sequential processing

开发者 https://www.devze.com 2023-04-03 12:01 出处:网络
This is a java based backend system. First let me explain the existing system: There is order processor system that consumes orders from a queue. When an order arrives, payment system is called whic

This is a java based backend system. First let me explain the existing system:

There is order processor system that consumes orders from a queue. When an order arrives, payment system is called which first acquires lock on item row based on item_id. If there are 1000 orders in the queue, order processor will consume them and will continue calling payment processor.

Please note that order processor and payment processors are independent systems that communicate via web services.

If payment processor has multiple orders for the same item, the processing would fail with LockAcquisition error which propagates to order processor too which will then resend failed orders to payment processor at a later time. Orders may be retried anywhere in next 24 to 48 hours.

Now I have to improve this logic. I have to find out how this processing can be sequential for the orders with same item id (call paymentProcessor when lock is released).

Order Proces开发者_开发百科sor may be processing 1000 items and multiple threads are carrying out the processing. I do know the item id for each of these orders. I recently moved to backend development and I thought I need an insight from experts to know how it can be done in best possible way. Any pointers will be much appreciated.

Thanks in advance!!


It's hard to give good advice without fully understanding the architecture. One strategy that would solve the problem at the expense of some efficiency would be to dispatch orders to specific threads based on a specific dispatching strategy, e.g. if you have 10 threads, you could take the order ID (or hash of the order ID) modulo 100 and dispatch to that thread number.

You will findthat your threads are somewhat underutilized because distribution will not be completely even, but that should resolve the issue.

If you go that route, take care to properly handle creating/terminating/crashing of processing threads.

0

精彩评论

暂无评论...
验证码 换一张
取 消