Async Research
SpringBoot @Async: The magic and the gotchas
Fixing Production issue with @Async in Spring Boot this is an article that discusses the solution of database connections not closing after calling.
Difference Between CompletableFuture And Future In Java
some good information on async and transactional Spring @Async: null hibernate session on LAZY collection)
@Transactional(readOnly=true) a silver bullet?
When using async you have to make sure that although all the rest endpoints, services are async and running in parallel, you must and should maintain database data integrity when you make use of async this will be lost, in the java persistence API we have @Transactional annotation it makes sure that all of then happen in a session context and is managed by the JPA/Hibernate, so no matter how ever async we become we always get blocked at the database level, this can be mitigated in two ways I believe
- heavily use
Transactional(readOnly=true)and separate all the get request@Repositoryand use the@Transactionalblock only on those which actually read and write to the database. - use a read only database for all read operations which is a slave. all write operations to the master DB which is the master and replicated to the read only DB, how we maintain up to date data is for a later discussion.
although the second option might not be the best for production, maybe the first one can be tested out