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

Domain-Driven Data at That Conference

Domain-Driven Data at That Conference

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 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

August 09, 2016
Tweet

More Decks by Bradley Holt

Other Decks in Programming

Transcript

  1. Bradley Holt, Developer Advocate
    Tuesday, August 9, 2016
    @BradleyHolt
    Domain-Driven Data

    View Slide

  2. View Slide

  3. @BradleyHolt

    View Slide

  4. View Slide

  5. View Slide

  6. View Slide

  7. Big Data
    Get it?

    View Slide

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

    View Slide

  9. A Brief History of Data

    View Slide

  10. 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 Slide

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

    View Slide

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

    View Slide

  13. 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 Slide

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

    View Slide

  15. Changing Constraints

    View Slide

  16. Always On

    View Slide

  17. Big Data

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  21. Enter "Not only SQL" (NoSQL)

    View Slide

  22. @BradleyHolt
    key-value
    graph
    document
    …more

    View Slide

  23. @BradleyHolt

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  27. Domain-Driven Design (DDD)

    View Slide

  28. @BradleyHolt

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  34. Entities
    Entities are defined by their identity

    View Slide

  35. Value Objects
    Value objects encode attributes that describe things

    View Slide

  36. Aggregates
    Aggregates group related entities to minimize complexity

    View Slide

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

    View Slide

  38. 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 Slide

  39. Choosing the Right Data Layer

    View Slide

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

    View Slide

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

    View Slide

  42. 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 Slide

  43. Strategic Design

    View Slide

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

    View Slide

  45. 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 Slide

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

    View Slide

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

    View Slide

  48. @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 (e.g.
    Apache Spark)

    View Slide

  49. Alternative Architectures

    View Slide

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

    View Slide

  51. 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 Slide

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

    View Slide

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

    View Slide

  54. View Slide

  55. 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 Slide

  56. 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 Slide

  57. Questions?
    @BradleyHolt

    View Slide

  58. View Slide