Let's say I have multiple REST applications where I need to store fairly limited data which the applications will maintain (CRUD) and process data per user request. The data will be always small enough to keep it in the memory which is a big performance boost and also much easier data manipulation since it's directly java object. As a bonus it makes websocket-push implementation much easier.
But, this data must be persisted (be available after shutdown or crash) and also be available to other servers via network connection (scaling).
One way to accomplish this would be I guess using PostgreSQL
's JSON
capabilities with Notify
feature. Or I guess a NoSQL database with some sort of notify functionality will do as well. Those require a lot of boilerplate code/SQL around each table. I prefer to have something simpler or a wrapper that does it for me.
An example in my head:
public class MyRestResource {
// This map will be updated realtime if any other service updates it; and when it's updated it will update the database.
private Map<String, MyPojo> myPojos;
public MyRestResource(PojoSynchronizer pojoSynchronizer){
// getTable will return a special Map implementation with events and triggers and being observed by the pojoSynchronizer.
this.myPojos = pojoSynchronizer.getTable("myPojos", MyPojo.class);
}
}
Of course this is just one approach with probably many challenges. It could be a different implementation. Is something like this available? Or can a wrapper written easily using the approaches above like PostgreSQL JSON and Notify
?