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

Domain-Driven Data at SunshinePHP

Bradley Holt
February 09, 2018

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
  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
  3. Brent Spiner with Zoltar from Big by Bradley Holt, on

    Twitter <https://twitter.com/BradleyHolt/status/702311271002087424>. Big Data
  4. IBM Cloud / February 9, 2018 / © 2018 IBM

    Corporation A Brief History of Data
  5. 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 <https://flic.kr/p/7Frdi> (CC BY 2.0).
  6. Relational databases guarantee atomicity, consistency, isolation, and durability (ACID) IBM

    Cloud / February 9, 2018 / © 2018 IBM Corporation Hard Disk by Jeff Kubina, on Flickr <https://flic.kr/p/uS4zk> (CC BY-SA 2.0).
  7. 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 <https://flic.kr/p/bu2gfG> (CC BY 2.0).
  8. 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 <https://flic.kr/p/cacNad> (CC BY 2.0).
  9. 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 <https://flic.kr/p/d41HES> (CC BY 2.0).
  10. IBM Cloud / February 9, 2018 / © 2018 IBM

    Corporation Changing Constraints
  11. 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 <https://flic.kr/p/ebpwib> (CC BY-SA 2.0).
  12. IBM Cloud / February 9, 2018 / © 2018 IBM

    Corporation Big Data World travel and communications recorded on Twitter by Eric Fischer, on Flickr <https://flic.kr/p/b7ntgR> (CC BY 2.0).
  13. IBM Cloud / February 9, 2018 / © 2018 IBM

    Corporation The CAP Theorem Consistency Availability Partition Tolerance
  14. 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 <https://flic.kr/p/cfXKY1> (CC BY 2.0).
  15. 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 <https://flic.kr/p/z4hgz1> (CC BY 2.0).
  16. IBM Cloud / February 9, 2018 / © 2018 IBM

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

    Corporation key-value graph document …more database by Tim Morgan, on Flickr <https://flic.kr/p/7DUk5> (CC BY 2.0).
  18. 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 <https://flic.kr/p/z6P3RM> (CC BY 2.0).
  19. 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 <https://flic.kr/p/aZjTXv> (CC BY-ND 2.0).
  20. 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 <https://flic.kr/p/ao19br> (CC BY-ND 2.0).
  21. IBM Cloud / February 9, 2018 / © 2018 IBM

    Corporation Domain-Driven Design (DDD)
  22. 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 <https://flic.kr/p/k7Mp2C> (CC BY-SA 2.0).
  23. 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 <https://flic.kr/p/4pC77a> (CC BY-ND 2.0).
  24. Models are tools used to solve problems within the domain

    IBM Cloud / February 9, 2018 / © 2018 IBM Corporation model by MaZzuk, on Flickr <https://flic.kr/p/3fUREM> (CC BY 2.0).
  25. 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 <https://flic.kr/p/2z4udd> (CC BY-SA 2.0).
  26. IBM Cloud / February 9, 2018 / © 2018 IBM

    Corporation Building Blocks of DDD and Domain Object Life Cycle
  27. Entities are defined by their identity IBM Cloud / February

    9, 2018 / © 2018 IBM Corporation DSC_3407 by Mad House Photography, on Flickr <https://flic.kr/p/7EUfbx> (CC BY 2.0).
  28. Value objects encode attributes that describe things IBM Cloud /

    February 9, 2018 / © 2018 IBM Corporation red numbers by DaveBleasdale, on Flickr <https://flic.kr/p/6hkJWo> (CC BY 2.0).
  29. Aggregates group related entities to minimize complexity IBM Cloud /

    February 9, 2018 / © 2018 IBM Corporation Social graph by Dmitry Grigoriev, on Flickr <https://flic.kr/p/fnzLPk> (CC BY 2.0).
  30. Repositories provides the illusion of in- memory data stores IBM

    Cloud / February 9, 2018 / © 2018 IBM Corporation Catalog. by Adam Mayer, on Flickr <https://flic.kr/p/282Bh> (CC BY-SA 2.0).
  31. 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..*]
  32. IBM Cloud / February 9, 2018 / © 2018 IBM

    Corporation Choosing the Right Data Layer
  33. 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 <https://flic.kr/p/a8dwVr> (CC BY 2.0).
  34. 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 <https://flic.kr/p/5rnE8S> (CC BY 2.0).
  35. “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/
  36. IBM Cloud / February 9, 2018 / © 2018 IBM

    Corporation Strategic Design
  37. 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 <https://flic.kr/p/iPpAs8> (CC BY 2.0).
  38. 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 <https://flic.kr/p/e9sTjU> (CC BY-SA 2.0).
  39. 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 <https://flic.kr/p/4a3Yyk> (CC BY-SA 2.0).
  40. 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 <https://flic.kr/p/fpLRzV>.
  41. 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
  42. IBM Cloud / February 9, 2018 / © 2018 IBM

    Corporation Alternative Architectures
  43. 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 <https://flic.kr/p/wHWeTA> (CC BY 2.0).
  44. 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
  45. 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 <https://flic.kr/p/4tfcMy> (CC BY 2.0).
  46. Thank you IBM Cloud / February 9, 2018 / ©

    2018 IBM Corporation Bradley Holt Developer Advocate Senior Software Engineer — ibm.com