How to handle events in service fabric
Hi Team,
I am working on migrating the database tables to service fabric microservices. As part of publishing the services, the existing data also migrated from the Database to Service fabric service.
In the initial phase, I don't want to replace the entire database with microservices and would like to maintain both databases and microservices. In order to maintain data integrity between microservices and databases, we have tried two approaches.
Approach 1 a separate database service and EventGird messaging system.
Below is the flow to maintain data integrity between microservices and database:
Migrate data from database to service fabric ( As part of service publishing).
Create a record in service fabric
Publish an event to EventGird based on EventType(Create, Update, Delete, DeletePermanent)
The API endpoints (Webhooks) will listen to EventGrid and perform the respective action based on the eventType a. CreateRecord --> Create a record in database b. UpdateRecord --> Updates the record in database c. DeleteRecord --> Deletes the record in database. DeleterecordPermanent --> Deletes the record permanently from the database
The above approach is working without any issues.
Approach 2 We implemented a new service EventHandler Service similar to EventGrid.
Below is the flow to maintain data integrity between microservices and database:
Migrate data from database to service fabric ( As part of service publishing).
Create a record in service fabric
Publish an event to EventHandler based on EventType(Create, Update, Delete, DeletePermanent)
The API endpoints (Webhooks) will listen to EventHandler and perform the respective action based on the eventType a. CreateRecord --> Create a record in database b. UpdateRecord --> Updates the record in database c. DeleteRecord --> Deletes the record in database. DeleterecordPermanent --> Deletes the record permanently from the database
The two approaches are working without any issues. However, I am looking for one of the optimal\ best ways to publish events and process them.
Any suggestions or inputs?