Microservices gets it WRONG defining Service Boundaries

  Рет қаралды 11,734

CodeOpinion

2 жыл бұрын

Logical boundaries aren't physical boundaries. A service boundary can be a 1:1 mapping of logical and physical but they don't have to be. A logical boundary can have many physical boundaries and a physical boundary can be composed of many components from many logical boundaries. Do we have microservices to thank for the idea that the physical, development, and logical views of a system are the same? This introduces a pile of unneeded complexity related to deployment, versioning, and data duplication.
🔗 EventStoreDB
eventsto.re/codeopinion
🔔 Subscribe: kzbin.info/door/3RKA4vunFAfrfxiJhPEplw
💥 Join this channel to get access to source code & demos!
kzbin.info/door/3RKA4vunFAfrfxiJhPEplwjoin
🔥 Don't have the JOIN button? Support me on Patreon!
www.patreon.com/codeopinion
📝 Blog: codeopinion.com
👋 Twitter: codeopinion
✨ LinkedIn: www.linkedin.com/in/dcomartin/
📧 Weekly Updates: mailchi.mp/63c7a0b3ff38/codeopinion
0:00 Intro
0:33 Physical Boundaries
2:43 4+1 Architectural View Model
3:39 Logical Boundaries
5:47 Complexity
#softwarearchitecture #softwaredesign #microservices

Пікірлер: 79
@Tony-dp1rl
@Tony-dp1rl Жыл бұрын
I always find it amusing how good microservices design looks almost identical to individual small monoliths, and how the microservices of today are often larger than monoliths of 10 years ago in terms of code size and resources needed.
@croncoder862
@croncoder862 2 жыл бұрын
Most people doing microservices today have a distributed monolith. Large states moving from service to service with versioning as a huge problem, prone to cascading failures, vague boundaries, vague understanding of which service should handle a cascading failure. Moreover like you mentioned, you really cannot spin up an instance independently which was the whole point of building a standalone service. Lastly testing is a nightmare.
@mikemccarthy9855
@mikemccarthy9855 2 жыл бұрын
Thank you for this video! I think this is the first time I've seen someone explicitly show an example between the logical view and the physical view where the database logically is "split", but physically is the SAME database, with the logical split happening at the schema level. Lots of people miss this when developing microservices. Almost every SOA/microservice system I've seen in the last 15 years (except for one) all have the same development view, logical view and physical view. Separate visual studio solution per microservice and separate database. It does NOT have to be like this. A lot of people this same physical vs. logical view mistake when using CQRS. A separate write store and read store does not mean you have to use two separate databases. You can achieve logical separation using schema, relational db views, and other patterns like state changes only happen view commands, and reads only happen via a db's LINQ provider or a repository layer.
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Ya, I often mention a relational db view as well and I usually get confused looks. It's a runtime generated projection.
@ChrisVisserDev
@ChrisVisserDev 2 жыл бұрын
You're hitting the nail on the head with this one. Mixing up logical boundaries with physical boundaries is one of the most common and expensive mistakes I see happening. To make matters worse, lots of companies also base their entire team structure on this wrong split making it very hard to recover from this mistake
@IgorRoztr
@IgorRoztr Жыл бұрын
Man, always when I watch one of your videos and then see a list of your other videos I am like "Yeah, that's the exact set of next questions that I have". Great content for serious backend devs ;)
@marna_li
@marna_li Жыл бұрын
Often developers choose to bulld microservices for one characteristic specifically. Then they disregard the rest. Not actually understanding boundaries.
@drewjaqua2905
@drewjaqua2905 2 жыл бұрын
Another great video ... immaculate timing, too, since this is directly relevant to what I'm working on.
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Perfect!
@shahrazkl
@shahrazkl Жыл бұрын
Than you, this is one of the issues I see in the most of dev team worked with.
@ryanelfman3520
@ryanelfman3520 2 жыл бұрын
Great video thanks
@MerrionGT6
@MerrionGT6 2 жыл бұрын
Data change ownership is key - your data only "belongs" in one domain even if other domains can ask about it or request changes to it.
@Jonas-Seiler
@Jonas-Seiler Жыл бұрын
Having every tiny little feature live in its own repo also makes it nearly impossible to statically reason about how business processes actually function and to think about what existing systems can be used to implement new processes.
@Jonas-Seiler
@Jonas-Seiler Жыл бұрын
Even better when most of the projects have abbreviated or non descriptive names and their purpose isn’t documented anywhere either.
@egorsozonov7425
@egorsozonov7425 2 жыл бұрын
Another example of that is code itself. It may be tempting to split code for different microservices into physically different repos, but then you create hurdles for sharing code between them.
@FlaviusAspra
@FlaviusAspra 2 жыл бұрын
Two terms you haven't mentioned but you've touched on: monorepo, vertical slicing. Thought I'd pitch in.
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Thanks. I was going to mention monorepo when talking about 4+1 and the development view.
@vikas6024
@vikas6024 2 жыл бұрын
Thanks for another great video.
@m1dway
@m1dway 2 жыл бұрын
on 07:50, I'm a bit confused. What do you mean by having a local data cache on other boundary could mean wrong logical boundary? What if the local cache is needed to display the data? Or here's a scenario. Let's say, I have a service that sending message to other user. Now, part of the process of sending the message, I would need to perform validation whether the user exists or not. My Question is, what should be done here? Should this message service perform RPC calls to identity service to validate the existence of the user, or should the message service holds the local cache of the list of available users mirroring the identity service?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
It depends why you want or need the data as a local cache. If it's for display purposes (eg, product name), sure, but if it's for data that's required for business logic, that's when I'd start digging into why that data is owned in another boundary.
@hrtummala
@hrtummala 2 жыл бұрын
Nice presentation on the differences but the question I have is what should I do when my logical boundary is required by multiple physical boundaries? Can I then say my logical boundary = physical boundary to determine the capacity to serve multiple physical systems?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
They can be the same, they just don't have to be. Logical boundaries can be coupled to other logical boundaries, preferably though async messaging.
@shilashm5691
@shilashm5691 2 жыл бұрын
Hi Derek, Is event-driven architecture t a way that medicare or services communicate with each other in an async way? And then, event sourcing, event notification, cqrs, event carried state transfer are just a patterns in event driven arch that we can implement. Please reply back!
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Yes. Check out a video I did about a lot of what you're asking: kzbin.info/www/bejne/p3ynY4yLia90jq8
@kimstacks
@kimstacks 2 жыл бұрын
So in the context of the 4+1, a service boundary belongs to process view? or the scenario view?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
The service boundary is everything in 4+1. 4+1 details the different "views".
@giuliocasa1304
@giuliocasa1304 2 жыл бұрын
I think I perfectly agree with the spirit of this video especially for traditional infrastructures. I still have some doubts about cloud scaling options. Maybe this is not really related to video, this can be considered off topic, but I try to ask. The point is that - from the perspective of concurrency in a 12 factors app as well as in an event driven architecture like keda on k8s - you end up scaling pods based on some queue mechanism. I consider that a physical boundary because it triggers the number of physical nodes in a cluster. But in modern languages (f#, golang, even c# and scala somehow) you have an async task model that is different from, say, old classical java spring boot jms (which in turn works well with some activemq or rabbitmq, hence with keda). That modern async model is really a logical boundary: indeed tasks or goroutines are not in 1:1 correspondence with low level os processes (how can they be correctly intercepted by kubernetes scaling metrics? I don't think they easily can). In conclusion I'm afraid that it's very difficult for an app that is not designed as the expected microservices cloud native app to scale well on the kubernetes cluster. The cause of logical boundaries becoming also physical boundaries could be the "dockerization pattern", this cloud native approach to the cloud infrastructure where we no longer have single virtual machines, but only containerized, ephemeral, immutable pod processes, for which the physical and logical boundaries intrinsically fade into one another
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Yes, the "dockerization" I think contributed to it. But I was also pointed out from Udi Dahan on Twitter, that his goes back farther to the "Web Services" days of SOAP. Which I agree with as well when I think back to it (yes, I'm old).
@giuliocasa1304
@giuliocasa1304 2 жыл бұрын
@@CodeOpinion I'm afraid I'm also old... because I remember those years. But if I open a book I bought at that prehistoric time - rational unified process - it reads like the architectural model has more views (4+1) among which there is the *logical* view that is distinct from the *implementation* view and from the *deploy* view... Somehow similar to the concepts you've expressed here... Correct? I was trying to say that instead docker and kubernetes (to some extent) tightened/overlapped together those old different views in the "cloudy" concept of pod/container/deployment. Also the concept itself of devop can be imagined as a fusion of dev (=logical view?) and ops (=physical view? =the old deploy and implementation views of the years of rational unified process?). But I surrender here and I stop. Because I absolutely don't want to confirm that we are old and/or we are saying old things!))
@chrisl8292
@chrisl8292 Жыл бұрын
​@@CodeOpinion if that makes you old, then I'm downright ancient from my DCOM and. NET Remoting days! 😅
@FISS007
@FISS007 2 жыл бұрын
Hi Derek, I am a complete beginner/new commer to DDD and your channel is a gold mine =) So thank you for putting all that effort in sharing your knowledge. One technical concept that i can't wrap my head around regarding to separating domains is regarding entities that are cross domains by nature, like Users for example. A user is referenced in every single domaine, and every domain needs to access user informations (like username and whatnot). Let me give a concrete example: 1/ Let us say that we have an ordering, sales, purchases and inventory domains, each with its own transactions. We want to be able to display the username of the user that performed the transaction when displaying the lists of transactions. 2/ We also want to be able to have some audit data recorded per entity, ie the user that created and last updated the entity, and when displaying the list of the said entity, we also whant to display the username of the related user for the entire list. I know i asked a lot already but i will be forever grateful if you could give a small example user EF =) Thank you in advance.
@CodeOpinion
@CodeOpinion 2 жыл бұрын
As an example, I usually have a 'user' that tied to every command/query/event. Every request from the outside API (eg http API) gets generally translated to a message that also contains some identification of the user the initiated it. It's not the entire "user" just some identification of them and possibly roles/permissions etc. (Think identify/claims)
@FISS007
@FISS007 2 жыл бұрын
@@CodeOpinion So, each domain defines its 'user' within its database ? or are we "allowed" from a DDD perspective to let all domains cross boundary with the one and only domain that owns the user (a sort of controlled coupling) ?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Each wouldn't likely need it's own user. The identity passed around with messages would serve most purposes.
@FISS007
@FISS007 2 жыл бұрын
@@CodeOpinion Ok, if i am getting you right, There will bo no foreign key constraint between, let's say the Order table and a "User" table in the Sales DB, the Order will only hold a simple flat ID and the username. When deleting the user or altering it, Domain Events will allow to keep everything in sync. Is that right ? Thank you.
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Yes to the first part. No need to keep anything "in sync" since just referencing identifiers
@Jkmbowa
@Jkmbowa 2 жыл бұрын
Great video, I have question on 2 logical boundary on one database. By allowing one logical boundary access the data of another through the database would this introduce coupling as the first logical boundary would need to what data to query for, for example Or have I misunderstood?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
No, you wouldn't be allowing a logical boundary to access the data of another logical boundary. What I was intending to describe is that the schema/data can live on the same physical database instance.
@thescourgeofathousan
@thescourgeofathousan 2 жыл бұрын
@@CodeOpinion you literally said that the benefit would be that the collocated service could just access the data it would otherwise have had to retrieve from the other service via rpc (your first of several straw men).
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Clearly, I didn't articulate that well. What I was attempting to say is if you needed data in another logical boundary for business logic purpose, it's likely that you have boundaries wrong, and that feature is in the wrong logical boundary. Even if it was in a different physical boundary, it could reach out to the db directly, if it's in the correct logical boundary.
@thescourgeofathousan
@thescourgeofathousan 2 жыл бұрын
@@CodeOpinion what a horrific suggestion.
@wanbeeler5891
@wanbeeler5891 2 жыл бұрын
@@CodeOpinion wondering if there’s is an example that could clarify. Showing the incorrect and refactoring into a better logical boundary.
@sajad5644
@sajad5644 2 жыл бұрын
great video , can you create a course about microservices ? your explanation always is great
@CodeOpinion
@CodeOpinion 2 жыл бұрын
I'll be putting something out sooner or later. I wouldn't call it about "microservices" rather having a well defined logical boundaries and loose coupling between them.
@jahedurrahman3181
@jahedurrahman3181 2 жыл бұрын
@@CodeOpinion I’m waiting!
@rodneydias9586
@rodneydias9586 2 жыл бұрын
Great video
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Thanks!
@thedacian123
@thedacian123 2 жыл бұрын
When this design is met.I mean on bounded context doesn't map to a single app,but to many apps services which may be sharing the same database or multiple databases?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Bounded context owns it's data and schema. Don't share it directly, provide ways for other boundaries to retrieve that data if required (for good reasons) via a defined API or messages.
@lytung1532
@lytung1532 Жыл бұрын
The tutorial is useful. I have a scenario that i want to build a API to get the list of all orders of the current user. Each order will include the following info: -Product name, product category: collected from product service -Shipping info from shipping service -Payment info from payment service ... If i understand you correctly composing the related info should be handled at UI or some kind of API composer service? There's also an use case where we need to validate stock availability from inventory service to make sure there's any order is created and failed after that due to stock unavailability issue. Could you share idea how to solve that kind of problem?
@CodeOpinion
@CodeOpinion Жыл бұрын
Stock availability in a warehouse doesn't really work like that but if you are just using an example of requiring a guarantee on the qty, check out this video on the reservation pattern: kzbin.info/www/bejne/hovQYYWHfMimaZo
@thedacian123
@thedacian123 Жыл бұрын
Sorry but i don;t get it.A phisycal boundry is a application web or worked, which is a deployment unit (has behind it a container/process and an repo) whereas a logical boundry is a subsystem,could be made of some physical apps.Is this correct?Thank you!
@CodeOpinion
@CodeOpinion Жыл бұрын
Correct. A physical boundary is a unit of deployment. A logical boundary is a cohesive grouping of features and data ownership.
@Rotem_shwartz
@Rotem_shwartz 2 жыл бұрын
Isn’t placing multiple services inside one docker container risky? Like what if one of them goes down? It may effect the others
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Depends. Generally yes, I'd agree assuming you want the isolation.
@wildrice8199
@wildrice8199 Жыл бұрын
It's true logical and physical boundaries are not the same, but it's not as if separating different services onto different physical structures is a thoughtless choice. If you have two services sharing the same physical database, if that database goes down, both services go down. Any sharing of physical resources increases coupling between services.
@CodeOpinion
@CodeOpinion Жыл бұрын
My guess is smaller teams creating bigger systems would be better served in making this distinction to reduce physical/deployment complexity where it's just not needed.
@GilliamFlebus
@GilliamFlebus 2 жыл бұрын
It would be very nice to consume your content as a podcast. I feel like that format might be more appropriate.
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Hmmm interesting 🤔
@raghavanmk
@raghavanmk 2 жыл бұрын
Noob question .. can two logical boundaries share a db ? Say if communication across autonomous components is via ids and detailed information about the ids is in a db, can the db be shared ?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
I would say the physical database server/instance can be, but the schema (tables) shouldn't be.
@raghavanmk
@raghavanmk 2 жыл бұрын
@@CodeOpinion thanks for response. So each autonomous component could share a physical db instance but will have their own schema ? If so, just hypothesising could it lead to data redundancy ? Or is it like more contextual ? And In such scenarios we may pass more than an id ?
@Tony-dp1rl
@Tony-dp1rl Жыл бұрын
This should have more Likes
@CodeOpinion
@CodeOpinion Жыл бұрын
Agreed 😂
@barryels
@barryels 2 жыл бұрын
Great video once again, thank you. The use of schemas as an isolation strategy over a shared database doesn't seem to be that popular, at least from my minimal research into the topic in the .NET ecosystem. Is that an accurate assessment?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
My guess would be most are breaking everything up physically. It has benefits in doing so, my point was it doesn't have to be.
@thescourgeofathousan
@thescourgeofathousan 2 жыл бұрын
Entire video is an attempt to rationalise tight coupling of the implementation of logical entities. Fail. Solution complexity should only be reduced to get it as close to problem space complexity as possible and no further. You’re basically adhering to the KISS principle here: Keep It Stupidly Simple. Additionally your introduction of rpc as the only alternative to event-based as a means of state change is the first appendage in the strawman you built to justify your desire for micro-tight-coupling to save you from the reality of the complexity required to solve the problem space of loose coupling and independently evolvable solutions. Calling into question the very fabric of event-based state management is an even more laughable part of your wickerman. Presented as simply an annoying complication to this implementation mechanism it would in fact render the who concept a non-starter. If I could pinpoint your root problem it would be that you present a set of issues that could simply be removed from the equation without requiring the tight physical coupling solution as a reason to do so. It is painful to watch you guys try to recreate the lessons we learned in the mid-2000’s due to tool vender and consultancy disinformation campaigns of the 20teens and go in the wrong directions (ie running back toward bad decisions we were moving away from before hand). This is why the IT industry is so cyclical: every time we make progress towards simplicity that actually solves problems across the breadth of the value-stream it cuts tool vendors and cookie-cutter consultants out of the reward chain and they respond with a campaign to embrace and redirect the effort into a corrupted form they can profit from and then sit back and watch reactionary developers run back towards the old ways thinking they are running to awards new ones with new understandings of “how they are ok if we do it this way or that” (new jargon to justify old bad ideas). Once you live long enough to see the cycles it becomes extremely disheartening to watch.
@CodeOpinion
@CodeOpinion 2 жыл бұрын
I'm at a loss for a response. I'll take the blame and say that I clearly did not explain my intention very well. I say this because you wrote "the first appendage in the strawman you built to justify your desire for micro-tight-coupling". The entire video is exactly about not tightly coupling between logical boundaries by forcing them to be physical boundaries as well. Anyways, thanks for the comment.
@thescourgeofathousan
@thescourgeofathousan 2 жыл бұрын
@@CodeOpinion but you ARE tightly coupling! Just in the physical space rather than the logical. That may solve the problem you see in one space but it causes a whole bunch of others across the entire value stream. A) I hope you are not trying to achieve DEcoupling rather than loose coupling. B) you can’t solve coupling in one space by moving it to another. That’s just playing the shell game and moving issues around solves nothing.
@CodeOpinion
@CodeOpinion 2 жыл бұрын
@@thescourgeofathousan I have no idea how this video is inferring that I'm talking about tight coupling. My intent in this video is to call out that logical boundaries aren't physical boundaries. They can be the same but they don't have to be. I'm not advocating anything more than explaining they aren't the same thing. That's it. My intent (as in most of my videos) is to define logical boundaries that that defined by functional cohesion (business capabilities) with data ownership. These logical boundaries are loosely coupled and interact by messaging to remove temporal coupling. How you define that on a physical aspect and deployment is another thing entirely. I appreciate the comment but I think we're on two different worlds.
@thescourgeofathousan
@thescourgeofathousan 2 жыл бұрын
@@CodeOpinion you’ve advocated or at the very least suggested it might not be a terrible idea to couple multiple services together in physical space.
@CodeOpinion
@CodeOpinion 2 жыл бұрын
@@thescourgeofathousan I never said couple. UI composition is a good example of that. Components from logical boundaries can be composed in the same UI. That's a deployment and composition concern. If you disagree, so be it, I'm clearly not going to change your mind :)