Currently when I build applications, I build them as one big monolithic application such that everything resides in a single compiled assembly and the data resides in one single SQL database (with some redis/elasticsearch used as support). This works relatively well for my purposes, but I would like to move towards designing micro service architectures. However I have a hard time understanding how any relational integrity is maintained when your services/databases are spread across several servers.
Observe the following diagram:
In this example, the Identity service is is separate from the Ordering service. Obviously the Identity Microservice would need to be fetching user data from a database with things like firstname, lastname, passwords, roles/claims, etc.
Obviously other parts of the system have relations with the user. For example, every order is probably tied to the user who placed that order. In a traditional SQL database, you would simply have a foreign key to keep the relational integrity. With the above diagram the "Ordering Microservice" looks completely independent from the user database. How is relational integrity maintained in such an architecture? Does the ordering service just insert an "Order" record with the user's ID without maintaining any relationship anywhere? What happens if that user is then deleted from the system. In this particular example you would probably still want to maintain the order data, but there are lots of examples where you would want to delete data related to that user when the user is deleted. In a microservice architecture it seems like this all has to be done manually with a lot of room for error.