This question is about implementation and architecture of Async nature of tasks implemented via REST to improve performance.
Imagine an application which is suppose to push data from external service to different domain services. Later on, it is expected that multiple request will query previously push data from other domain service.
As an example, Consider a real-estate application which collects home/apartments/commercial-shops information from different other websites.
-
STEP-1: User logs in
At this point it is expected that this user might query about list of apartments available for rent in whole city
It is also expected that user might query about list of houses on Sale
-
STEP-2: User navigate from Home page to
Available for Rent
Menu -
STEP-3: User clicks on Menu and services started to collect data from different other external systems/websites
Now, our goal is to run a task to collect all available houses for rent/sale as soon as User logs in which is not a problem. But the challenge is that if this job to collect data is not finished and user clicked on Available for Rent
Menu, How would be block this API to respond until Background job is finished.
Please keep in mind that overall System is implemented via Microservices based on CQRS pattern.
So in total, There are four service GATEWAY, COLLECTION, RENT, SALE
So when User logs in
- Endpoint of Service
gateway/EP1
will receive request which will triggercollection-service
to start the data collection job. - Collection job is suppose to collect info and update
RENT
service. - Collection job is suppose to collect info and update
SALE
service. - Now if user clicks on
Available for Rent
Menu which will callgateway/EP2
and this endpoint of gateway service collects info from serviceRENT
(which is being updated bycollection
service).
So Problem statement is ,How a gateway service endpoint can put on wait until one microservice updates another microservice?
Observer pattern
can be a candidate here but I need experts opinion if it is best suited in above mentioned Rest microservices architecture.
Aucun commentaire:
Enregistrer un commentaire