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

Domain-Driven Data at SunshinePHP

Domain-Driven Data at SunshinePHP

There are many types of databases and data analysis tools from which to choose today. Should you use a relational database? How about a key-value store? Maybe a document database? Or is a graph database the right fit for your project? What about polyglot persistence? Help! Applying principles from Domain-Driven Design such as strategic design and bounded contexts, this session will help you choose and apply the right data layer for your application's model or models. We'll explore traditional relational databases, graph databases, document databases, key/value stores, polyglot persistence, CQRS, event sourcing, and data layers for microservices.

Bradley Holt

February 09, 2018
Tweet

More Decks by Bradley Holt

Other Decks in Programming

Transcript

  1. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Domain-Driven Data

    Bradley Holt
    Developer Advocate
    Senior Software Engineer

    View full-size slide

  2. A fully-managed
    database-as-a-service
    (DBaaS) based on
    Apache CouchDB with
    additional full text and
    geospatial search
    capabilities
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation

    View full-size slide

  3. Open for Data Dome (outside) by Bradley Holt.

    View full-size slide

  4. Brent Spiner with Zoltar from Big by Bradley Holt, on Twitter .
    Big Data

    View full-size slide

  5. IBM
    Cloud
    Data
    Services
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation

    View full-size slide

  6. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    A Brief History of Data

    View full-size slide

  7. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    The Relational Database
    order
    *order_id
    customer_id
    date
    customer
    line_item
    *customer_id
    email_address
    name
    *order_id
    *item_id
    price
    quantity
    database 2 by Tim Morgan, on Flickr (CC BY 2.0).

    View full-size slide

  8. Relational databases
    guarantee atomicity,
    consistency,
    isolation, and
    durability (ACID)
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Hard Disk by Jeff Kubina, on Flickr (CC BY-SA 2.0).

    View full-size slide

  9. The ACID guarantees
    provided by relational
    databases were (and
    often still are) critical
    for systems of record
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    IBM 360 Announcement center by Robert Nix, on Flickr (CC BY 2.0).

    View full-size slide

  10. The introduction of the
    Web brought new
    types of applications
    with different
    constraints than
    systems of record
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Dialing Up Web History by Mike Licht, on Flickr (CC BY 2.0).

    View full-size slide

  11. The introduction of
    mobile apps added to
    the growing number of
    systems of
    engagement
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Instagram and other Social Media Apps by Jason Howie, on Flickr (CC BY 2.0).

    View full-size slide

  12. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Changing Constraints

    View full-size slide

  13. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Always On
    Dynamo, un siècle de lumière et de mouvement dans l'art, 1913 – 2013 by Yann Caradec, on Flickr (CC BY-SA 2.0).

    View full-size slide

  14. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Big Data
    World travel and communications recorded on Twitter by Eric Fischer, on Flickr (CC BY 2.0).

    View full-size slide

  15. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    The CAP Theorem
    Consistency Availability
    Partition
    Tolerance

    View full-size slide

  16. Horizontal scaling
    through the addition of
    commodity hardware
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Server grill with blue light by David Precious, on Flickr (CC BY 2.0).

    View full-size slide

  17. Every node in an
    eventually consistent
    distributed system will
    eventually arrive at a
    consistent state if
    given no new updates
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Spider Web by Alden Chadwick, on Flickr (CC BY 2.0).

    View full-size slide

  18. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Enter “Not only SQL” (NoSQL)

    View full-size slide

  19. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    key-value
    graph
    document
    …more
    database by Tim Morgan, on Flickr (CC BY 2.0).

    View full-size slide

  20. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation

    View full-size slide

  21. Key-value stores
    provide opaque data
    accessed through
    unique keys
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Keys for the Stanley Hotel by Mike Silva, on Flickr (CC BY 2.0).

    View full-size slide

  22. Document databases
    are a variation on key-
    value stores with
    strictly defined values
    (e.g. JSON objects)
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    paper by malik, on Flickr (CC BY-ND 2.0).

    View full-size slide

  23. Graph databases
    provide nodes and
    properties of nodes
    connected via edges
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Edinburgh Road Network analysis by Steven Kay, on Flickr (CC BY-ND 2.0).

    View full-size slide

  24. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Domain-Driven Design (DDD)

    View full-size slide

  25. Domain-Driven Design
    is a collaboration
    between domain
    experts and software
    practitioners
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    IMG_2619 by Jason Pelletier, on Flickr (CC BY-SA 2.0).

    View full-size slide

  26. Complexity is in the
    domain, not in the
    technology
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Sounds_of_Complexity11.jpg by Enzo Varriale, on Flickr (CC BY-ND 2.0).

    View full-size slide

  27. Models are tools used
    to solve problems
    within the domain
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    model by MaZzuk, on Flickr (CC BY 2.0).

    View full-size slide

  28. Don't confuse models
    with reality—the map
    is not the territory
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    taking the subway to find the rents by Eli Duke, on Flickr (CC BY-SA 2.0).

    View full-size slide

  29. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Building Blocks of DDD and
    Domain Object Life Cycle

    View full-size slide

  30. Entities are defined by
    their identity
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    DSC_3407 by Mad House Photography, on Flickr (CC BY 2.0).

    View full-size slide

  31. Value objects encode
    attributes that
    describe things
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    red numbers by DaveBleasdale, on Flickr (CC BY 2.0).

    View full-size slide

  32. Aggregates group
    related entities to
    minimize complexity
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Social graph by Dmitry Grigoriev, on Flickr (CC BY 2.0).

    View full-size slide

  33. Repositories provides
    the illusion of in-
    memory data stores
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Catalog. by Adam Mayer, on Flickr (CC BY-SA 2.0).

    View full-size slide

  34. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Domain Layer
    Order Aggregate
    «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

  35. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Choosing the Right Data Layer

    View full-size slide

  36. A repository cannot
    completely abstract
    the constraints of
    your data store
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Lina Bo Bardi, SESC Pompéia by paulisson miura, on Flickr (CC BY 2.0).

    View full-size slide

  37. Object-oriented
    programming and
    relational databases
    use different models,
    resuting in the
    object-relational
    impedance mismatch
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Financial District Classical Building Reflection Distortion, San Francisco, California, USA by Wonderlane, on Flickr (CC BY 2.0).

    View full-size slide

  38. “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)
    Software Engineering Radio Episode 226:
    Eric Evans on Domain-Driven Design at 10 Years, 2015
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    http://www.se-radio.net/2015/05/se-radio-episode-226-eric-evans-on-domain-driven-design-at-10-years/

    View full-size slide

  39. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Strategic Design

    View full-size slide

  40. Bounded contexts
    allow different models
    to be used within
    different domain
    contexts
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    rectangles by Dean Hochman, on Flickr (CC BY 2.0).

    View full-size slide

  41. Each bounded context
    should have its own
    data layer, and should
    not directly access a
    data layer belonging to
    a different bounded
    context
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Hexagons by Henry Burrows, on Flickr (CC BY-SA 2.0).

    View full-size slide

  42. A data layer may be a
    database, or it can be
    a data system
    consisting of multiple
    databases—
    sometimes called
    polyglot persistence
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    FLOWERS Mixed Boquet by kazandrew, on Flickr (CC BY-SA 2.0).

    View full-size slide

  43. Each bounded context
    may be represented
    as a microservice or a
    cluster of
    microservices
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Rainforest Biome by BMiz, on Flickr .

    View full-size slide

  44. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    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

  45. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Alternative Architectures

    View full-size slide

  46. Rather than update an
    entity in place,
    Command Query
    Responsibility
    Segregation (CQRS)
    provides separate
    read and write models
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    rectangles-10 by Karen Cropper, on Flickr (CC BY 2.0).

    View full-size slide

  47. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Domain Layer
    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

  48. Event sourcing is an
    architecture in which
    application state is
    computed from a
    sequence of events
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Rusty Chain by veggiefrog, on Flickr (CC BY 2.0).

    View full-size slide

  49. IBM
    Cloud
    Data
    Services
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation

    View full-size slide

  50. Thank you
    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation
    Bradley Holt
    Developer Advocate
    Senior Software Engineer

    ibm.com

    View full-size slide

  51. IBM Cloud / February 9, 2018 / © 2018 IBM Corporation

    View full-size slide