Reputation: 133
I have a service AircraftsService which handles all data about an aircraft, an aircraft type and so on. And I have a Service FlightsService which handles all data about flights. I have to link an aircraft to a flight.
Normally I would create a foreign key in the flights table that links by aircraft. But in a microservice architecture I have domains and separate databases.
How can I represent this?
I could have a database for all aircraft and a database for all flights. The flights table becomes an indirect foreign key to the aircraft. When I call the flight service it calls the aircraft service with the id from the flights table, then builds the response. I do not call the aircraft database directly from the flight service. When I delete an aircraft I have to tell the flight service that it does not exist any more and the flight service has to update the indirect foreign key.
Is my solution correct?
What is best practice?
Upvotes: 7
Views: 3152
Reputation: 1467
There are various ways of best database practices when dealing in micro services , it may differ with respect to domain of the entities which are being used , and also the scope of your application use.
There are few best practices for database design in micor services , to start with listing few of them
1 - Private-tables-per-service – each service owns a set of tables that must only be accessed by that service
2 - Schema-per-service – each service has a database schema that’s private to that service
3 - Database-server-per-service – each service has it’s own database server.
You can mix and match these are per your data size and data count.
I would like you to refer and go through this page for a perfect example.
Microservices Database Best practices
Identify the load on each service that you will have. Load can be counted in 2 ways.
Then you can decide the appraoch.
Upvotes: 2