6 ms·
My comment, slightly edited, from the previous posting of this, at https://news.ycombinator.com/item?id=9106813 https://news.ycombinator.com/item?id=9106813 >
by davidw 12y ago
My comment, slightly edited, from the previous posting of this, at https://news.ycombinator.com/item?id=9106813 https://news.ycombinator.com/item?id=9106813
> One kind of coupling that people tend to overlook as they transition to a microservices architecture is database coupling, where all services talk to the same database and updating a service means changing the schema. You need to split the database up and denormalize it.
That sounds like a decision you wouldn't want to take lightly; the kind of thing you might do once your company is already big. I wouldn't want to start out that way though, it sounds like a recipe for a mess.
- anonymousDan 12y agoYes I just came in here to write a comment along those lines. I mean surely you're opening a whole can of worms in terms of consistency etc. I get the feeling Netflix happens not to have use cases where strong consistency is a requirement. I'd be interested to get more detail about how they went about the transition - even just pointers to more on the meta-data management tools they use.
- davidkellis 12y agoThe consistency problem is an open question in my mind. I definitely don't like the idea of having some data synchronization tool to fix the inconsistent data across services problem. I wonder what the best practice is for maintaining data consistency across services. Does anyone know?
- shanemhansen 12y agoIdeally you don't have to sync the data because one service owns that data. Other services request that data via api. In a RESTful world those api requests are cacheable.
- davidkellis 12y agoBut what about the situation where you have an entity service that owns the data for one piece of the domain, for example a People service, and then other services, like the Address service and the Billing service, reference a particular person. In that scenario, I can imagine the Address service and the Billing service would have a foreign key referencing a person in the People service. Then, what happens if the Person gets deleted? In that case, we've got a consistency problem, even though each service owned its data. Is the best practice to not use entity services?
- cgh 12y agoThe "each service owns its data" scenario shouldn't take precedence over cases like this, where consistency is aligned with obvious business rules. If Person gets deleted, then "on delete cascade" should take care of that Person's Address and Billing records. For updates and maybe reads, it's a different story.
- davidkellis 12y agocgh, I've hit the reply limit, but I wanted to ask how you'd implement the cascade deletes thing over services? Would the People service have to emit events describing that a person was deleted that the Address and Billing services would be expected to subscribe to in order to handle that the person was deleted?
- cgh 12y agoSorry, I should have been more clear. I'm assuming a shared database. So cascading deletes would be defined in the table's schema. Let's pretend we're using Postgresql: \d Person [A bunch of table schema stuff] Referenced by: TABLE "Billing" CONSTRAINT "billing_id_fk" FOREIGN KEY (id) REFERENCES Person(id) ON DELETE CASCADE (I typed that off the type of my head so it might not be quite correct.)
- dsp1234 12y agoThe original position being argued though was "... where all services talk to the same database... You need to split the database up and denormalize it.". So the basic premise is that there is no shared database, and thus having the database enforce cascading deletes is not an option.
- BerislavLopac 12y agoIf the two (the database schema and the microservices API) are designed and maintained separately, this assertion (that "updating a service means changing the schema") is not necessarily true. They have separate responsibilities -- the database is persisting the data, and the services provide some business logic, and while they might need to change together this is not always the case.
- nl 12y agoDatabase-as-an-integration-layer is a well known anti-pattern. It's tempting because it's easy, and at first glance it seems to solve lots of problems (consistency, communication etc). It's a big mistake. If multiple service are reading and writing from the same DB it rapidly becomes impossible to change things. Things like input validation changes suddenly have to be implemented in multiple places (which is hard), and done simultaneously (which often becomes hard enough to stop work being done). In a microservice based approach, the data flows though shared services, and so changes can be done in fewer places. (Note that read-only, reporting-style databases are separate. I think there is a good case for these being shared)
- dragonwriter 12y agoMultiple services reading from the same DB can -- and should -- be using different accounts that have access to different objects that abstract the underlying data model from the various clients and keep them loosely coupled. This is almost as old of a recommendation as relational DBs themselves. You can create a tightly coupled design with a shared DB, but there is nothing inherent with shared DB integration requires that.