Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Domain-Driven Data at ConFoo Montreal

Domain-Driven Data at ConFoo Montreal

Applying principles from Domain-Driven Design such as strategic design and bounded contexts, this presentation will help you choose and apply the right data layer for your application's model or models. We will explore traditional relational databases, graph databases, document databases, key/value stores, polyglot persistence, CQRS, event sourcing, and data layers for microservices.

Bradley Holt

March 09, 2017
Tweet

More Decks by Bradley Holt

Other Decks in Programming

Transcript

  1. ConFoo Montreal
    Bradley Holt, Developer Advocate
    Thursday, March 9, 2017
    Domain-Driven Data
    @BradleyHolt

    View full-size slide

  2. @BradleyHolt

    View full-size slide

  3. Big Data
    Get it?

    View full-size slide

  4. IBM Cloud Data Services
    Open for Data
    A comprehensive por.olio of open source data services

    View full-size slide

  5. A Brief History of Data

    View full-size slide

  6. The Relational Database
    @BradleyHolt
    order
    *order_id
    customer_id
    date
    customer
    line_item
    *customer_id
    email_address
    name
    *order_id
    *item_id
    price
    quantity

    View full-size slide

  7. ACID Guarantees
    Relational databases guarantee atomicity, consistency, isolation and durability

    View full-size slide

  8. Big Iron
    The ACID guarantees provided by relational databases were (and often still are) critical
    for systems of record

    View full-size slide

  9. The World Wide Web
    The introduction of the Web brought a whole new type of application with
    different constraints than systems of record
    @BradleyHolt

    View full-size slide

  10. Mobile Apps
    The introduction of mobile apps added to the growing number of systems of engagement

    View full-size slide

  11. Changing Constraints

    View full-size slide

  12. The CAP Theorem
    @BradleyHolt
    Partition
    Tolerance
    Availability
    Consistency
    Consistency Availability
    Partition
    Tolerance

    View full-size slide

  13. Horizontal Scaling
    Horizontal scaling is scaling through the addition of commodity hardware

    View full-size slide

  14. Eventual Consistency
    Given no new updates, each node in a distributed system will eventually have a
    consistent view of the data

    View full-size slide

  15. Enter "Not only SQL" (NoSQL)

    View full-size slide

  16. @BradleyHolt
    key-value
    graph
    document
    …more

    View full-size slide

  17. @BradleyHolt

    View full-size slide

  18. Key-Value Stores
    Opaque data accessed through unique keys

    View full-size slide

  19. Document Databases
    A variation on key-value stores with strictly defined values (e.g. JSON objects)

    View full-size slide

  20. Graph Databases
    Nodes and properties of nodes connected via edges

    View full-size slide

  21. Domain-Driven Design (DDD)

    View full-size slide

  22. @BradleyHolt

    View full-size slide

  23. Domain-Driven Design
    A collaboration between domain experts and software practitioners

    View full-size slide

  24. Complexity is in the Domain
    Complexity is in the domain, not in the technology

    View full-size slide

  25. Models as Tools
    Models are tools used to solve problems within the domain

    View full-size slide

  26. The Map is not the Territory
    Don't confuse models with reality itself

    View full-size slide

  27. Building Blocks of DDD and the
    Life Cycle of a Domain Object

    View full-size slide

  28. Entities
    Entities are defined by their identity

    View full-size slide

  29. Value Objects
    Value objects encode attributes that describe things

    View full-size slide

  30. Aggregates
    Aggregates group related entities to minimize complexity

    View full-size slide

  31. Repositories
    A repository provides the illusion of an in-memory data store

    View full-size slide

  32. Domain Layer
    Order Aggregate
    @BradleyHolt
    «interface»
    OrderRepository
    + insertOrder(order:Order)
    + updateOrder(order:Order)
    + findOrderById(id:int) : Order
    + recentOrders([limit:int]) : Order[0..*]
    Customer

    Infrastructure Layer
    LineItem

    Order
    - id : int
    - customer : Customer
    - date : Date
    - lineItems : LineItem[1..*]
    + total() : Money
    InMemoryOrderRepository
    + insertOrder(order:Order)
    + updateOrder(order:Order)
    + findOrderById(id:int) : Order
    + recentOrders(limit:int) : Order[0..*]
    RelationalMapperOrderRepository
    + insertOrder(order:Order)
    + updateOrder(order:Order)
    + findOrderById(id:int) : Order
    + recentOrders(limit:int) : Order[0..*]

    View full-size slide

  33. Choosing the Right Data Layer

    View full-size slide

  34. Data Store
    A repository cannot abstract the constraints of your data store

    View full-size slide

  35. Object-Relational Impedance Mismatch
    Object-oriented programming and relational databases use different models

    View full-size slide

  36. Eric Evans on NoSQL
    "This is the world of NoSQL to me, that we can choose a tool that fits well with
    the problem we're trying to solve." –Eric Evans (author of Domain-Driven Design)
    @BradleyHolt

    View full-size slide

  37. Strategic Design

    View full-size slide

  38. Bounded Context
    Bounded contexts allow different domain models to be used within different contexts

    View full-size slide

  39. One Data Layer Per Bounded Context
    Each bounded context should have its own data layer, and should not directly access a
    data layer belonging to another bounded context

    View full-size slide

  40. Data Systems
    A data layer may be a database, or it can be a data system consisting of multiple databases

    View full-size slide

  41. Microservices as Bounded Context
    Represent each bounded context as a microservice or a cluster of microservices

    View full-size slide

  42. @BradleyHolt
    Catalog
    Document Database
    Key/Value Store
    Graph Database
    Full Text Search
    Shopping
    Cart
    Document Database
    Key/Value Store
    Orders Relational Database
    Big Data Analytics

    View full-size slide

  43. Alternative Architectures

    View full-size slide

  44. Command Query Responsibility Segregation (CQRS)
    Rather than update an entity in place, CQRS provides separate read and write models

    View full-size slide

  45. Domain Layer
    @BradleyHolt
    Read Model
    «interface»
    OrderQueryHandler
    + findOrderById(id:int) : OrderDetails
    + recentOrders([limit:int]) : OrderSummary[0..*]
    Write Model
    OrderDetails
    + getId() : int
    + getCustomer() : Customer
    + getDate() : Date
    + getLineItems() : LineItem[1..*]
    + getTotal() : Money
    «interface»
    OrderCommandHandler
    + handle(command:CreateOrder)
    + handle(command:AddLineItem)
    CreateOrder
    - customer : Customer
    - date : Date
    - lineItems : LineItem[1..*]
    OrderSummary
    + getId() : int
    + getDate() : Date
    + getTotal() : Money
    AddLineItem
    - orderId : int
    - lineItem : LineItem

    View full-size slide

  46. Event Sourcing
    The current application state is computed from a sequence of events

    View full-size slide

  47. IBM Cloud Data Services
    Open for Data
    A comprehensive por.olio of open source data services

    View full-size slide

  48. Image Credits
    §  Open for Data Dome (outside) by Bradley Holt
    §  Open for Data Dome (inside) by Bradley Holt
    §  Brent Spiner (Data from Star Trek: The Next Generation) with
    Zoltar from Big by Bradley Holt, on Twitter

    §  database 2 by Tim Morgan, on Flickr
    §  Hard Disk by Jeff Kubina, on Flickr
    §  IBM 360 Announcement center by Robert Nix, on Flickr

    §  Dialing Up Web History by Mike Licht, on Flickr

    §  Instagram and other Social Media Apps by Jason Howie, on Flickr

    §  Dynamo, un siècle de lumière et de mouvement dans l'art, 1913 – 2013
    - Galeries nationales du Grand Palais - Paris - 10 avril au 22 juillet 2013
    by Yann Caradec, on Flickr §  World travel and communications recorded on Twitter by Eric Fischer,
    on Flickr
    §  Server grill with blue light by David Precious, on Flickr

    §  Spider Web by Alden Chadwick, on Flickr
    §  database by Tim Morgan, on Flickr
    §  Keys for the Stanley Hotel by Mike Silva, on Flickr

    §  paper by malik, on Flickr
    §  Edinburgh Road Network analysis by Steven Kay, on Flickr

    @BradleyHolt

    View full-size slide

  49. Image Credits (cont'd)
    §  IMG_2619 by Jason Pelletier, on Flickr
    §  Sounds_of_Complexity11.jpg by Enzo Varriale, on Flickr

    §  model by MaZzuk, on Flickr
    §  taking the subway to find the rents by Eli Duke, on Flickr

    §  DSC_3407 by Mad House Photography, on Flickr

    §  red numbers by DaveBleasdale, on Flickr
    §  Social graph by Dmitry Grigoriev, on Flickr
    §  Catalog. by Adam Mayer, on Flickr
    §  Lina Bo Bardi, SESC Pompéia by paulisson miura, on Flickr

    §  Financial District Classical Building Reflection Distortion, San Francisco,
    California, USA by Wonderlane, on Flickr
    §  Eric Evans by Oliver Gierke, on Flickr
    §  rectangles by Dean Hochman, on Flickr
    §  Hexagons by Henry Burrows, on Flickr
    §  Rooted by Anna Levinzon, on Flickr
    §  Rainforest Biome by BMiz, on Flickr
    §  rectangles-10 by Karen Cropper, on Flickr
    §  Rusty Chain by veggiefrog, on Flickr
    @BradleyHolt

    View full-size slide

  50. Questions?
    @BradleyHolt

    View full-size slide