Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
DDD: Bounded Contexts

It was brought up indirectly in a comment on my last post … the idea of a Ubiquitous Language (UL) seems like it is too all encompassing. Indeed it is – unless you are working on a very simple application, one language just isn’t enough. Not only that, but a single “mammoth model” will also be too large, unwieldy, and eventually turn into a Big Ball of Mud. That is where the idea of Bounded Contexts come into the game.

Bounded Contexts in DDD is one of the “advanced” topics, it doesn’t even appear in the book until well over halfway. However, I am going to introduce it now, so that later in this series, the terms don’t become an obstacle… in the book you could flick a few hundred pages ahead, here you don’t have that luxury. Feel free to skip this post until later if it doesn’t make much sense now.

Suffice to say you could model your entire domain as a single thing, with a language to cover everything, but if you look at the business you are trying to model, it is unlikely that is how they see things.

An example of Context here would be within an ecommerce system. Although you could model this as a single system, it would also warrant splitting into separate Contexts. Each of these areas within the application have their own Ubiquitous Language, their own Model, and a way to talk to other Bounded Contexts to obtain the information they need.

Example Ecommerce Contexts

Well the obvious starting point would be the customer facing Context – let’s call this the Shopping Context – this is the part of the application that lets a customer browse the catalogue, search for items, pick items, and put them in their shopping basket.

You may be thinking this is it for a simple ecommerce system – and for a simple system it probably is. However on larger systems there are other Contexts that should probably come into play

When the customer clicks “checkout” then we need to process that order, this is going to involve the Ordering Context to take the shopping basket, process the payment and to create the relevant instructions for picking, the Inventory Context (which may have been involved earlier to display “items in stock”) to reserve the items in the warehouse,  and the list may go on depending on the scale of the entire application.

Each of these Bounded Contexts has a specific responsibility, and can operate in a semi-autonomous fashion. By splitting these apart it becomes more obvious where logic should sit, and we can avoid that BBOM.

Bounded Context or Context?

The term Context is a general description of a grouping of concepts, the term Bounded Context is more specific – a Bounded Context is an area of your application which has explicitly defined borders, has it’s own model, has it’s own Model, and maintains it’s own code. Within the Bounded Context everything should be strictly consistent.

Usually, we can use the terms Context and Bounded Context interchangeably, though I tend to talk in terms of Context about the business side of things, and the term Bounded Context about the technical implementation.

In essence, a Bounded Context is an application in it’s own right. By splitting your large application into many Contexts, you gain all the advantages of modularity, separation of concerns and loose coupling – but on a much larger scale than many developers often think.

Surely Bounded Context’s Must Interact?

Indeed they do need to. Within DDD this is done using a Context Map. Again, I will skip the details for now, but suffice to say, a Context Map is a clearly defined way of talking between Bounded Contexts. The book has a number of examples of how this could be implemented, and many more will become apparent as you progress. The Context Map is the contract your Bounded Context provides to the outside world, other Bounded Contexts

In Conclusion

We skipped a fair way ahead here, so don’t get too stuck up on Contexts, just bear in mind they exist, and they resolve issues around conflicting Ubiquitous Language terms, allow Models to focus on specific problems, and provide a loosely coupled application architecture.

Previously:

Domain Driven Design: A Step by Step Guide

DDD: The Ubiquitous Language

Reference

InfoQ Free eBook : Domain Driven Design Quickly

Domain-Driven Design: Tackling Complexity in the Heart of Software (Eric Evans)

Bounded Context

Context Map

del.icio.us Tags: DDD,Domain Driven Design,Practices and Principles


Posted 02-11-2009 8:38 AM by Jak Charlton

[Advertisement]

Comments

Adam B wrote re: DDD: Bounded Contexts
on 02-11-2009 7:59 AM

Do you have a link for any implementation (rather than definition) of a context map or do I have to wait :-)? I've so far resisted splitting my apps into bounded contexts because I've been unclear on things such as how they should interact with each other. Service layer on top or something like that?

Btw it's great that you're doing this series of posts.

Jak Charlton wrote re: DDD: Bounded Contexts
on 02-11-2009 9:24 AM

Adam,

A Context Map is a really general term in DDD - it covers a lot of software patterns. Eric uses a few in his book, examples of using a Service at each side of the Bounded Contexts.

These Services however could be anything, they could be in-process services that talk on a class level, or they could be a web service layer in a larger system, something like REST, or you could even go to the point where Bounded Contexts sit behind their own set of SOA services.

I guess the point is, the Bounded Context is important, as long as how the communicate is decoupled, then the actual mechanism for mapping is far less important.

What *is* important about the Context Map is that it is just like a Published API, it is fairly hard to change and therefore should be as right as possible. I recollect Eric refers to the Context Map as being the situation as it is there and then, behind the map the Domain may be in flux.

Apart from the benefit of logical and physical separation, this allows different teams to work on different Contexts, with little impact on each other until a Context Map needs to change - this change should happen after the Bounded Context it represents has changed

Dew Drop - February 11, 2009 | Alvin Ashcraft's Morning Dew wrote Dew Drop - February 11, 2009 | Alvin Ashcraft's Morning Dew
on 02-11-2009 9:48 AM

Pingback from  Dew Drop - February 11, 2009 | Alvin Ashcraft's Morning Dew

Adam B wrote re: DDD: Bounded Contexts
on 02-11-2009 10:16 AM

Thanks I think I get it, it should be as if you are consuming a third party api, however it happens to be implemented which is of course up to you. Makes sense.

DotNetShoutout wrote DDD: Bounded Contexts - Casey Charlton - Insane World
on 02-11-2009 10:37 AM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Casey Charlton - Insane World wrote DDD: There Is No Database
on 02-12-2009 2:27 AM

Do not try to bend the spoon; that's impossible. Instead only try to realize the truth: There is

Community Blogs wrote DDD: There Is No Database
on 02-12-2009 3:11 AM

Do not try to bend the spoon; that's impossible. Instead only try to realize the truth: There is

Reflective Perspective - Chris Alcock » The Morning Brew #285 wrote Reflective Perspective - Chris Alcock » The Morning Brew #285
on 02-12-2009 3:32 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #285

Casey Charlton - Insane World wrote DDD : Command Query Separation as an Architectural Concept
on 02-12-2009 12:13 PM

There has been some confusion recently around a recent evolution of DDD, the idea of Command Query Separation

Community Blogs wrote DDD : Command Query Separation as an Architectural Concept
on 02-12-2009 12:23 PM

There has been some confusion recently around a recent evolution of DDD, the idea of Command Query Separation

Casey Charlton - Insane World wrote DDD: Entities and Value Objects
on 02-13-2009 10:19 AM

Finally, after 5 posts in the series, we get to the beginning point, the basis of all things… Entities

Community Blogs wrote DDD: Entities and Value Objects
on 02-13-2009 10:56 AM

Finally, after 5 posts in the series, we get to the beginning point, the basis of all things… Entities

Casey Charlton - Insane World wrote DDD: Where is the Code? Another Brief Interlude
on 02-14-2009 12:28 PM

Right about now I can hear murmurs, "I haven't seen any code yet" That is because I view

Community Blogs wrote DDD: Where is the Code? Another Brief Interlude
on 02-14-2009 12:58 PM

Right about now I can hear murmurs, "I haven't seen any code yet" That is because I view

Daniel Teng wrote Weekly links #1
on 02-15-2009 5:01 AM

关于敏捷

FixingtheAgileEngineeringProblemblog.gdinwiddie.com/.../fixing-the-agile-en...

Casey Charlton - Insane World wrote DDD: Aggregates and Aggregate Roots
on 02-16-2009 9:51 AM

Download the eBook of the Series so far … We are family I got all my sisters with me Sister Sledge Some

Community Blogs wrote DDD: Aggregates and Aggregate Roots
on 02-16-2009 10:30 AM

Download the eBook of the Series so far … We are family I got all my sisters with me Sister Sledge Some

Casey Charlton - Insane World wrote DDD: Services
on 02-17-2009 4:38 PM

There can be no word more common in development, and no word used for such a multitude of different things

Community Blogs wrote DDD: Services
on 02-17-2009 4:44 PM

There can be no word more common in development, and no word used for such a multitude of different things

Casey Charlton - Insane World wrote DDD: What Kind of Applications Is It Suited To?
on 02-18-2009 2:20 PM

In many conversations, and in many comments here, you hear phrases like “well that’s not really suited

Community Blogs wrote DDD: What Kind of Applications Is It Suited To?
on 02-18-2009 2:39 PM

In many conversations, and in many comments here, you hear phrases like “well that’s not really suited

Casey Charlton - Insane World wrote DDD: The Repository Pattern
on 02-20-2009 3:30 AM

I seem to have taken a fairly long time to get here, and it has been mentioned in passing, but now we

Community Blogs wrote DDD: The Repository Pattern
on 02-20-2009 4:11 AM

I seem to have taken a fairly long time to get here, and it has been mentioned in passing, but now we

Casey Charlton - Insane World wrote DDD: Living In The Enterprise
on 02-21-2009 4:25 AM

No, not that Enterprise! The other Enterprise – the big amorphous one that organisation spent a fortune

Community Blogs wrote DDD: Living In The Enterprise
on 02-21-2009 4:48 AM

No, not that Enterprise! The other Enterprise – the big amorphous one that organisation spent a fortune

Insane World wrote DDD: Living In The Enterprise
on 02-21-2009 10:42 AM

No, not that Enterprise! The other Enterprise – the big amorphous one that organisation spent a fortune

Insane World wrote DDD: The Repository Pattern
on 02-21-2009 10:42 AM

I seem to have taken a fairly long time to get here, and it has been mentioned in passing, but now we

DDD Step By Step wrote DDD: There Is No Database
on 02-22-2009 3:32 PM

Do not try to bend the spoon; that's impossible. Instead only try to realize the truth: There is

DDD Step By Step wrote DDD : Command Query Separation as an Architectural Concept
on 02-22-2009 3:33 PM

There has been some confusion recently around a recent evolution of DDD, the idea of Command Query Separation

DDD Step By Step wrote DDD: Entities and Value Objects
on 02-22-2009 3:34 PM

Finally, after 5 posts in the series, we get to the beginning point, the basis of all things… Entities

DDD Step By Step wrote DDD: Aggregates and Aggregate Roots
on 02-22-2009 3:34 PM

Download the eBook of the Series so far … We are family I got all my sisters with me Sister Sledge Some

DDD Step By Step wrote DDD: Services
on 02-22-2009 3:35 PM

There can be no word more common in development, and no word used for such a multitude of different things

DDD Step By Step wrote DDD: What Kind of Applications Is It Suited To?
on 02-22-2009 3:36 PM

In many conversations, and in many comments here, you hear phrases like “well that’s not really suited

DDD Step By Step wrote DDD: The Repository Pattern
on 02-22-2009 3:36 PM

I seem to have taken a fairly long time to get here, and it has been mentioned in passing, but now we

DDD Step By Step wrote DDD: Living In The Enterprise
on 02-22-2009 3:37 PM

No, not that Enterprise! The other Enterprise – the big amorphous one that organisation spent a fortune

Insane World wrote DDD: Living In The Enterprise
on 02-26-2009 4:08 PM

No, not that Enterprise! The other Enterprise – the big amorphous one that organisation spent a fortune

Insane World wrote DDD: The Repository Pattern
on 02-26-2009 4:08 PM

I seem to have taken a fairly long time to get here, and it has been mentioned in passing, but now we

Czy ty te?? nadu??ywasz procedur sk??adowanych? « !FrAgile Thinking wrote Czy ty te?? nadu??ywasz procedur sk??adowanych? « !FrAgile Thinking
on 03-05-2009 5:10 PM

Pingback from  Czy ty te?? nadu??ywasz procedur sk??adowanych? « !FrAgile Thinking

DDD: Bounded Contexts at Mark Needham wrote DDD: Bounded Contexts at Mark Needham
on 03-08-2009 3:31 AM

Pingback from  DDD: Bounded Contexts at Mark Needham

QCon London 2009: What I’ve learned about DDD since the book - Eric Evans at Mark Needham wrote QCon London 2009: What I’ve learned about DDD since the book - Eric Evans at Mark Needham
on 03-13-2009 6:58 AM

Pingback from  QCon London 2009: What I’ve learned about DDD since the book - Eric Evans at Mark Needham

Billy McCafferty wrote Drawing the Line Between MVC Controllers and DDD Application Services
on 09-16-2009 2:28 PM

Frequently, when we adapt new technologies or techniques, the new fix ends up introducing new "yucky"

Billy McCafferty wrote Drawing the Line Between MVC Controllers and Application Services
on 09-16-2009 2:32 PM

Frequently, when we adapt new technologies or techniques, the new fix ends up introducing new "yucky"

Billy McCafferty wrote Greenfield Development with ASP.NET MVC & S#arp Lite - Day 2
on 10-12-2012 6:25 PM

A series of posts providing proven guidance for developing ASP.NET MVC applications from idea to well

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)