SlideShare a Scribd company logo
1 of 56
Download to read offline
Domain-Driven Design
Useful Models for Complex Problems

           Eric Evans
       domainlanguage.com
Why bother with models?
„We should do a nice design, but
    we just don‟t have time.‟
„Modeling and design take extra
 time, but they pay off in the long
               run.‟
Modeling and design are often the
 quickest path to the actual goal.
What is your goal?
• Implement this feature?
• Complete a releasable set of stories with
  an acceptable level of bugs?
• Deliver a release that the team can
  continue to extend in the next release?
• Deliver a clear and cohesive user
  experience?
Critical Complexity Is


The critical complexity of most software
 projects is in understanding the domain
 itself.
Shipping Domain
Long Beach, CA to Dallas, TX
     Via rail voyage XYZ




Hong Kong to Long Beach, CA
Via vessel voyage ABC
Cargo                  origin
                                 destination
cargoId                                        Routing Service
                                 cargoId
origin
                                 ...
destination
weight                                                  populate
                                                        cargo_bookings table




     Database table: cargo_bookings
     Cargo_ID Voyage_ID Load_Loc Unload_Loc
Cargo                  origin
                                 destination
cargoId                                        Routing Service
                                 cargoId
origin
                                 ...
destination
weight                                                  populate
                                                        cargo_bookings table




     Database table: cargo_bookings
     Cargo_ID Voyage_ID Load_Loc Unload_Loc
                                                                 side effect
Cargo                  origin
                                 destination
cargoId                                        Routing Service
                                 cargoId
origin
                                 ...
destination
weight                                                  populate
                                                        cargo_bookings table




     Database table: cargo_bookings
     Cargo_ID Voyage_ID Load_Loc Unload_Loc



                               “Give the routing service the
                                required origin, destination,
                                 and arrival time, and so on,
                               and it will look up the stops the
                                cargo will have to make and
                                  put them in the database.”
Cargo                  origin
                                 destination
cargoId                                        Routing Service
                                 cargoId
origin
                                 ...
destination
weight                                                  populate
                                                        cargo_bookings table




     Database table: cargo_bookings
     Cargo_ID Voyage_ID Load_Loc Unload_Loc



                               “Give the routing service the
                                required origin, destination,
   “Each table row               and arrival time, and so on,
   shows load and              and it will look up the stops the
      unload.”                  cargo will have to make and
                                  put them in the database.”
Cargo                  origin
                                 destination
cargoId                                        Routing Service
                                 cargoId
origin
                                 ...
destination
weight                                                  populate
                                                        cargo_bookings table




     Database table: cargo_bookings
     Cargo_ID Voyage_ID Load_Loc Unload_Loc




                                 “What concepts are we
                                       missing?”
Cargo                  origin
                                 destination
cargoId                                        Routing Service
                                 cargoId
origin
                                 ...
destination
weight                                                  populate
                                                        cargo_bookings table




     Database table: cargo_bookings
     Cargo_ID Voyage_ID Load_Loc Unload_Loc



                               “Give the routing service the
                                required origin, destination,
                                 and arrival time, and so on,
                               and it will look up the stops the
                                cargo will have to make and
                                  put them in the database.”
“A cargo makes a series of stops. At each stop it
  is unloaded from a transport and loaded onto
                   another.”
“A cargo’s
itinerary is a series
      of legs.”

                        “The cargo is loaded
                        onto a transport at the
                        beginning of a leg and
                        unloaded at the end.”
“A cargo’s
 itinerary gives
 instructions for
  each stop, to
unload and load
 onto a different
    transport.”
Stops or Legs?

Which is better?
What is a model?
Chinese Map
Mercator Map
Mercator Map
Some statements about this model
• The Earth is approximated as a sphere, with
  points of interest located on the surface.

• There are functions that map points on the
  surface of a sphere onto a cylinder
  (projections).

• Mercator‟s Projection preserves angles /
  direction of points relative to each other.
Defining Our Terms

domain A sphere of knowledge or activity.

model A system of abstractions
 representing selected aspects of the
 domain.

 A model is a distilled form of domain
 knowledge, assumptions, rules and
 choices.
It‟s not about “realism”

A model serves some use.

Usefulness is specific to particular scenarios.

There are always multiple models of the
 domain.
Stops or Legs?

Which is more useful?

   Useful for what?
Shipping Reference Scenarios

• Route and book a new shipment
Shipping Reference Scenarios

• Route and book a new shipment

• Reroute mid-transit at customer order
Long Beach, CA to Dallas, TX
     Via rail voyage XYZ




Hong Kong to Long Beach, CA
Via vessel voyage ABC
Hong Kong to Seattle, WA
Via vessel voyage DEF
Long Beach, CA to Seattle, WA
Via rail voyage UVW

                                     X

       Hong Kong to Long Beach, CA
       Via vessel voyage ABC
Cargo

           cargoId
           origin
           destination                               origin
           weight                                    destination                Routing Service
                                                     ...


                                                              an Itinerary with
                                                              appropriate origin/
{Itinerary must have origin, destination of Cargo}            destination
                           0..1

                     Itinerary

           /originLocationCode
           /destinationLocationCode
           /arrivalTime



                               *
                         Leg

           vesselVoyageId
           loadLocationCode
           /loadTime
           unloadLocationCode
           /unloadTime
Cargo

           cargoId
           origin
           destination                               origin
           weight                                    destination                Routing Service
                                                     ...


                                                              an Itinerary with
                                                              appropriate origin/
{Itinerary must have origin, destination of Cargo}            destination
                           0..1

                     Itinerary

           /originLocationCode
           /destinationLocationCode                       “Feed the specified
           /arrivalTime
                                                          origin, destination, and
                               *                          so on into the routing
                         Leg
                                                          service, and we get
           vesselVoyageId
           loadLocationCode
           /loadTime
                                                          back an itinerary that
           unloadLocationCode
           /unloadTime                                    meets the customer‟s
                                                          request.”
Cargo

           cargoId
           origin
           destination                               origin
           weight                                    destination                Routing Service
                                                     ...


                                                              an Itinerary with
                                                              appropriate origin/
{Itinerary must have origin, destination of Cargo}            destination
                           0..1

                     Itinerary

           /originLocationCode
           /destinationLocationCode
           /arrivalTime


                                                             “Each leg must load in
                               *
                         Leg                                 the same location as
           vesselVoyageId
           loadLocationCode                                  the previous legs
                                                             unload.”
           /loadTime
           unloadLocationCode
           /unloadTime
Yes, But What If…?

• Route and book a new shipment.

• Before each voyage arrival, issue
  purchase orders to vendors in the port
  for unloading, loading, storage and
  routing within the terminal.
„We have to get the model right
 first, before we write the code.‟
Up Front Analysis Locks in Ignorance

     • Models are distilled knowledge.

     • At the beginning of a project, the
       team is as ignorant as it will ever be.
There are always multiple models.
Blind Men and Elephant
Two Modelling Mistakes

• They keep trying to figure out the “true”
  nature of an elephant.

• They insist on just one model, in spite
  of incomplete information and possibly
  different goals.
Define Bounded Context
Bounded Context An operational
 definition of where a particular model is
 well-defined and applicable. (Typically a
 subsystem, or the work owned by a
 particular team).
Precision designs are fragile.

They require a bounded context
containing a unified model.
Not all of a large system will be
         well designed.
Where to look for more
• Model Exploration
  – domainlanguage.com/ddd/whirlpool
  – Section 3 in DDD book

• Context Boundaries
  – Chapter 14 in DDD book

• DDD Community (dddcommunity.org)
  – Experience reports
  – Discussion groups
杭州站 · 2011年10月20日~22日
 www.qconhangzhou.com(6月启动)




QCon北京站官方网站和资料下载
     www.qconbeijing.com

More Related Content

More from Yiwei Ma

Thoughtworks practice-hukai-qcon
Thoughtworks practice-hukai-qconThoughtworks practice-hukai-qcon
Thoughtworks practice-hukai-qconYiwei Ma
 
Ufida design-chijianqiang-qcon
Ufida design-chijianqiang-qconUfida design-chijianqiang-qcon
Ufida design-chijianqiang-qconYiwei Ma
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qconYiwei Ma
 
Netflix web-adrian-qcon
Netflix web-adrian-qconNetflix web-adrian-qcon
Netflix web-adrian-qconYiwei Ma
 
Google arch-fangkun-qcon
Google arch-fangkun-qconGoogle arch-fangkun-qcon
Google arch-fangkun-qconYiwei Ma
 
Cibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconCibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconYiwei Ma
 
Alibaba arch-jiangtao-qcon
Alibaba arch-jiangtao-qconAlibaba arch-jiangtao-qcon
Alibaba arch-jiangtao-qconYiwei Ma
 
Twitter keynote-evan-qcon
Twitter keynote-evan-qconTwitter keynote-evan-qcon
Twitter keynote-evan-qconYiwei Ma
 
Netflix keynote-adrian-qcon
Netflix keynote-adrian-qconNetflix keynote-adrian-qcon
Netflix keynote-adrian-qconYiwei Ma
 
Facebook keynote-nicolas-qcon
Facebook keynote-nicolas-qconFacebook keynote-nicolas-qcon
Facebook keynote-nicolas-qconYiwei Ma
 
Devjam keynote-david-qcon
Devjam keynote-david-qconDevjam keynote-david-qcon
Devjam keynote-david-qconYiwei Ma
 
Baidu keynote-wubo-qcon
Baidu keynote-wubo-qconBaidu keynote-wubo-qcon
Baidu keynote-wubo-qconYiwei Ma
 
淘宝线上线下性能跟踪体系和容量规划-Qcon2011
淘宝线上线下性能跟踪体系和容量规划-Qcon2011淘宝线上线下性能跟踪体系和容量规划-Qcon2011
淘宝线上线下性能跟踪体系和容量规划-Qcon2011Yiwei Ma
 
网游服务器性能优化-Qcon2011
网游服务器性能优化-Qcon2011网游服务器性能优化-Qcon2011
网游服务器性能优化-Qcon2011Yiwei Ma
 
Xietingbao-Qcon2011
Xietingbao-Qcon2011Xietingbao-Qcon2011
Xietingbao-Qcon2011Yiwei Ma
 
Wushi-Qcon2011
Wushi-Qcon2011Wushi-Qcon2011
Wushi-Qcon2011Yiwei Ma
 
BuilHigh Performance Weibo Platform-Qcon2011
BuilHigh Performance Weibo Platform-Qcon2011BuilHigh Performance Weibo Platform-Qcon2011
BuilHigh Performance Weibo Platform-Qcon2011Yiwei Ma
 
Optimize MySQL For Developers-Qcon2011
Optimize MySQL For Developers-Qcon2011Optimize MySQL For Developers-Qcon2011
Optimize MySQL For Developers-Qcon2011Yiwei Ma
 
大型视频网站单点分析与可用性提升-Qcon2011
大型视频网站单点分析与可用性提升-Qcon2011大型视频网站单点分析与可用性提升-Qcon2011
大型视频网站单点分析与可用性提升-Qcon2011Yiwei Ma
 
永不宕机的服务器-Qcon2011
永不宕机的服务器-Qcon2011永不宕机的服务器-Qcon2011
永不宕机的服务器-Qcon2011Yiwei Ma
 

More from Yiwei Ma (20)

Thoughtworks practice-hukai-qcon
Thoughtworks practice-hukai-qconThoughtworks practice-hukai-qcon
Thoughtworks practice-hukai-qcon
 
Ufida design-chijianqiang-qcon
Ufida design-chijianqiang-qconUfida design-chijianqiang-qcon
Ufida design-chijianqiang-qcon
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qcon
 
Netflix web-adrian-qcon
Netflix web-adrian-qconNetflix web-adrian-qcon
Netflix web-adrian-qcon
 
Google arch-fangkun-qcon
Google arch-fangkun-qconGoogle arch-fangkun-qcon
Google arch-fangkun-qcon
 
Cibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconCibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qcon
 
Alibaba arch-jiangtao-qcon
Alibaba arch-jiangtao-qconAlibaba arch-jiangtao-qcon
Alibaba arch-jiangtao-qcon
 
Twitter keynote-evan-qcon
Twitter keynote-evan-qconTwitter keynote-evan-qcon
Twitter keynote-evan-qcon
 
Netflix keynote-adrian-qcon
Netflix keynote-adrian-qconNetflix keynote-adrian-qcon
Netflix keynote-adrian-qcon
 
Facebook keynote-nicolas-qcon
Facebook keynote-nicolas-qconFacebook keynote-nicolas-qcon
Facebook keynote-nicolas-qcon
 
Devjam keynote-david-qcon
Devjam keynote-david-qconDevjam keynote-david-qcon
Devjam keynote-david-qcon
 
Baidu keynote-wubo-qcon
Baidu keynote-wubo-qconBaidu keynote-wubo-qcon
Baidu keynote-wubo-qcon
 
淘宝线上线下性能跟踪体系和容量规划-Qcon2011
淘宝线上线下性能跟踪体系和容量规划-Qcon2011淘宝线上线下性能跟踪体系和容量规划-Qcon2011
淘宝线上线下性能跟踪体系和容量规划-Qcon2011
 
网游服务器性能优化-Qcon2011
网游服务器性能优化-Qcon2011网游服务器性能优化-Qcon2011
网游服务器性能优化-Qcon2011
 
Xietingbao-Qcon2011
Xietingbao-Qcon2011Xietingbao-Qcon2011
Xietingbao-Qcon2011
 
Wushi-Qcon2011
Wushi-Qcon2011Wushi-Qcon2011
Wushi-Qcon2011
 
BuilHigh Performance Weibo Platform-Qcon2011
BuilHigh Performance Weibo Platform-Qcon2011BuilHigh Performance Weibo Platform-Qcon2011
BuilHigh Performance Weibo Platform-Qcon2011
 
Optimize MySQL For Developers-Qcon2011
Optimize MySQL For Developers-Qcon2011Optimize MySQL For Developers-Qcon2011
Optimize MySQL For Developers-Qcon2011
 
大型视频网站单点分析与可用性提升-Qcon2011
大型视频网站单点分析与可用性提升-Qcon2011大型视频网站单点分析与可用性提升-Qcon2011
大型视频网站单点分析与可用性提升-Qcon2011
 
永不宕机的服务器-Qcon2011
永不宕机的服务器-Qcon2011永不宕机的服务器-Qcon2011
永不宕机的服务器-Qcon2011
 

Domainlang keynote-eric-qcon

  • 1. Domain-Driven Design Useful Models for Complex Problems Eric Evans domainlanguage.com
  • 2. Why bother with models?
  • 3. „We should do a nice design, but we just don‟t have time.‟
  • 4. „Modeling and design take extra time, but they pay off in the long run.‟
  • 5. Modeling and design are often the quickest path to the actual goal.
  • 6. What is your goal? • Implement this feature? • Complete a releasable set of stories with an acceptable level of bugs? • Deliver a release that the team can continue to extend in the next release? • Deliver a clear and cohesive user experience?
  • 7. Critical Complexity Is The critical complexity of most software projects is in understanding the domain itself.
  • 9.
  • 10.
  • 11. Long Beach, CA to Dallas, TX Via rail voyage XYZ Hong Kong to Long Beach, CA Via vessel voyage ABC
  • 12. Cargo origin destination cargoId Routing Service cargoId origin ... destination weight populate cargo_bookings table Database table: cargo_bookings Cargo_ID Voyage_ID Load_Loc Unload_Loc
  • 13. Cargo origin destination cargoId Routing Service cargoId origin ... destination weight populate cargo_bookings table Database table: cargo_bookings Cargo_ID Voyage_ID Load_Loc Unload_Loc side effect
  • 14. Cargo origin destination cargoId Routing Service cargoId origin ... destination weight populate cargo_bookings table Database table: cargo_bookings Cargo_ID Voyage_ID Load_Loc Unload_Loc “Give the routing service the required origin, destination, and arrival time, and so on, and it will look up the stops the cargo will have to make and put them in the database.”
  • 15. Cargo origin destination cargoId Routing Service cargoId origin ... destination weight populate cargo_bookings table Database table: cargo_bookings Cargo_ID Voyage_ID Load_Loc Unload_Loc “Give the routing service the required origin, destination, “Each table row and arrival time, and so on, shows load and and it will look up the stops the unload.” cargo will have to make and put them in the database.”
  • 16. Cargo origin destination cargoId Routing Service cargoId origin ... destination weight populate cargo_bookings table Database table: cargo_bookings Cargo_ID Voyage_ID Load_Loc Unload_Loc “What concepts are we missing?”
  • 17. Cargo origin destination cargoId Routing Service cargoId origin ... destination weight populate cargo_bookings table Database table: cargo_bookings Cargo_ID Voyage_ID Load_Loc Unload_Loc “Give the routing service the required origin, destination, and arrival time, and so on, and it will look up the stops the cargo will have to make and put them in the database.”
  • 18. “A cargo makes a series of stops. At each stop it is unloaded from a transport and loaded onto another.”
  • 19. “A cargo’s itinerary is a series of legs.” “The cargo is loaded onto a transport at the beginning of a leg and unloaded at the end.”
  • 20. “A cargo’s itinerary gives instructions for each stop, to unload and load onto a different transport.”
  • 21. Stops or Legs? Which is better?
  • 22. What is a model?
  • 25.
  • 27. Some statements about this model • The Earth is approximated as a sphere, with points of interest located on the surface. • There are functions that map points on the surface of a sphere onto a cylinder (projections). • Mercator‟s Projection preserves angles / direction of points relative to each other.
  • 28.
  • 29. Defining Our Terms domain A sphere of knowledge or activity. model A system of abstractions representing selected aspects of the domain. A model is a distilled form of domain knowledge, assumptions, rules and choices.
  • 30. It‟s not about “realism” A model serves some use. Usefulness is specific to particular scenarios. There are always multiple models of the domain.
  • 31. Stops or Legs? Which is more useful? Useful for what?
  • 32. Shipping Reference Scenarios • Route and book a new shipment
  • 33. Shipping Reference Scenarios • Route and book a new shipment • Reroute mid-transit at customer order
  • 34. Long Beach, CA to Dallas, TX Via rail voyage XYZ Hong Kong to Long Beach, CA Via vessel voyage ABC
  • 35. Hong Kong to Seattle, WA Via vessel voyage DEF
  • 36. Long Beach, CA to Seattle, WA Via rail voyage UVW X Hong Kong to Long Beach, CA Via vessel voyage ABC
  • 37. Cargo cargoId origin destination origin weight destination Routing Service ... an Itinerary with appropriate origin/ {Itinerary must have origin, destination of Cargo} destination 0..1 Itinerary /originLocationCode /destinationLocationCode /arrivalTime * Leg vesselVoyageId loadLocationCode /loadTime unloadLocationCode /unloadTime
  • 38. Cargo cargoId origin destination origin weight destination Routing Service ... an Itinerary with appropriate origin/ {Itinerary must have origin, destination of Cargo} destination 0..1 Itinerary /originLocationCode /destinationLocationCode “Feed the specified /arrivalTime origin, destination, and * so on into the routing Leg service, and we get vesselVoyageId loadLocationCode /loadTime back an itinerary that unloadLocationCode /unloadTime meets the customer‟s request.”
  • 39. Cargo cargoId origin destination origin weight destination Routing Service ... an Itinerary with appropriate origin/ {Itinerary must have origin, destination of Cargo} destination 0..1 Itinerary /originLocationCode /destinationLocationCode /arrivalTime “Each leg must load in * Leg the same location as vesselVoyageId loadLocationCode the previous legs unload.” /loadTime unloadLocationCode /unloadTime
  • 40. Yes, But What If…? • Route and book a new shipment. • Before each voyage arrival, issue purchase orders to vendors in the port for unloading, loading, storage and routing within the terminal.
  • 41. „We have to get the model right first, before we write the code.‟
  • 42. Up Front Analysis Locks in Ignorance • Models are distilled knowledge. • At the beginning of a project, the team is as ignorant as it will ever be.
  • 43.
  • 44. There are always multiple models.
  • 45. Blind Men and Elephant
  • 46.
  • 47. Two Modelling Mistakes • They keep trying to figure out the “true” nature of an elephant. • They insist on just one model, in spite of incomplete information and possibly different goals.
  • 48. Define Bounded Context Bounded Context An operational definition of where a particular model is well-defined and applicable. (Typically a subsystem, or the work owned by a particular team).
  • 49.
  • 50.
  • 51.
  • 52.
  • 53. Precision designs are fragile. They require a bounded context containing a unified model.
  • 54. Not all of a large system will be well designed.
  • 55. Where to look for more • Model Exploration – domainlanguage.com/ddd/whirlpool – Section 3 in DDD book • Context Boundaries – Chapter 14 in DDD book • DDD Community (dddcommunity.org) – Experience reports – Discussion groups
  • 56. 杭州站 · 2011年10月20日~22日 www.qconhangzhou.com(6月启动) QCon北京站官方网站和资料下载 www.qconbeijing.com