We are using spring boot 1.5.10 Release version along with mongodbrepository.
We have huge data so we are loading static data(select * from table) on server startup using postconstruct.
Api response size is Approx 25MB we are compressing it using gzip so size becomes 5MB.
We have multiple services, every service includes @PostConstruct to load (select * from table)frequently used data to prepare maps to improve performance.
We are preparing map<id, custom Obj> from findall db query in each service 1 service for reference..
@PostCounstruct Init(){ List list = xyzRepository.findAll(); Map<String, MyObj> map = new HashMap(): for(MyObj Obj : list){ map.put(obj.id, Obj) } }
User will get fast response from map when findById / findAll / findByList(List employees> emps) called
Every month our db gets refreshed/updated. Once we refreshed db we are restarting spring boot application.
Problem which we are facing if there is any db refresh happened ( due to some issue/delay) within month in database, we need to restart server to get correct data instead of stale data.
We tried @Cacheable in every service but 1st db hit taking too much time.( As we are doing select * from table).
We made parallel ajax call to get data. Application dashboard need to plot data which is approx 30MB (gzip 5mb) which is pain..
Approx 2000 users for application 20 services.. Each service calling to get data ( some are getting static data from map which is initialised in postcounstruct)
Currently We are restarting server monthly when db refresh happened.
How we can get latest data without server restart when there is unexpected db refresh?
---------[Edit-1]-----
Upvoted answer suggest that populate new/update data in every map present in every service.
1.Application startup time will be high as map will be populated from database.
2.Overhead to populate/maintain data in some time interval(nightly/alternate day/Weekly) in Java maps.
What if more data will increase in each collection/table & every month.
Need expert review on upvoted answer.
Thanks for reading question