Do you know similar case with some example for this scenario? How could I implement it in Java / Spring 3/4 application?
I will simplify the scenario so it would be easy to understand. Firstly I am consuming REST / webservice with simple data: id of the product and its price. These data are changing in real time. Each customer logged into application will see different prices (base prices from the endpoint calculated using some margins and segments). Each customer must see these data in possible shortest time, so I could have a map in memory that has simple data for logged customers and their margins so I wouldnt have to query the database. I cant just do a simple loop checking this map because there will be thousands of customers logged in so the last one in the loop would have to wait even more than one second. I also cannot create new thread in Java for every customer logged in can I? Wouldnt it be too many threads?
I am planning to use Spring4 and maybe websockets abstraction in Spring 4 but I don't know how to implement and quarantee low latency for thousands of customers that have different calculations?
PriceVisibleForCustomer = Price + CustomerMargin
Price - changing every 300ms
CustomerMargn - some plus or minus amount that is resulting from customer agreement/segment/administrator decision etc. It doesnt change during customer http session
Customer - he takes part in the process after he logs in, he should see rapidly changing prices of 8 products.
private static void sendPricesToCustomers(Long productId,
Map<Long, BigDecimal> productIdToPriceMap,
Map<Long, BigDecimal> customerIdToMarginMap) {
for (Long customerId: customerIdToMarginMap.keySet()){
BigDecimal customerMargin = customerIdToMarginMap.get(customerId);
BigDecimal priceResult = productIdToPriceMap.get(productId).add(customerMargin);
}
}