简体   繁体   中英

How to manage updates in a springboot application

I am working on a springboot application, and I have to manage a particular use case.

Assume that we have a pipeline, where an an order containing an id and an amount is consumed by a kafka topic from IBM/AS400.

This order will be stored in a database, and used in Springboot for aggregations on an upper level of the application.

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Order implements Serializable {
        private string id;
        private String amount;
}

Let's assume that we have 2 orders, one with an amount of 500 and another one with an amount of 200.

This two orders will be used to compute a final amount, so the final amount is 700.

Let's assume, that we change the first order from 500 -> 1000.

The first idea was to use getOne(id) + save to update.

So it would be:

String newAmount = OrderRepository.getOne(1);
orderToUpdate.setAmount(newAmount);
orderRepository.save(orderToUpdate);

Since the order is used on an upper level of the application, and that updating this order will do a computation using 10 years of history, which will take a long time, Is there any way to solve this issue?

Please let me know, if you need more details !

Thanks in advance for your help

If you want to remove the aggregation completely, and I don't know how many times in a day aggregation happens, you could do the following

Assumptions

  1. Aggregation is performed only once a day
  2. Aggregated value is stored in a database and is thread-safe

Steps

  1. Take the new amount, find the difference between the previous amount and new amount
  2. Push the difference (as a real number) to a queue
  3. Persist the new amount
  4. From the queue, which has the ordered list of changed order values, apply the math on the persisted aggregated value, one by one.
  5. Audit the changes after each update to aggregated value.

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