Applying Domain Driven Design to
APIs and Microservices
James Higginbotham
james@launchany.com
@launchany
Great API Design is critical for
product adoption and long-term
API success
API design also tells a story
about your company and your
vision of what the world can
become.
Your API design defines the
capabilities or skills your API
offers to developers
Credit: http://kinlane.github.io/university-api-workshop/apis/
Architecture is design
API Design is an architectural
concern that combines business
drivers, product design, and
software design
Outside-In API Design Approach
 “My data model is not my object model”
– Data model is for internal storage
 “My object model is not my resource model”
– Resources is for external, context-based collaboration
– Object model is for internal software collaboration
 “My resource model is not my representation model”
– There are many ways to represent resources
e.g. JSON, XML, CSV, HTML
- Mike Amundsen, API-Craft Google Group
- https://groups.google.com/forum/#!search/my$20resource$20model$20is$20not/api-
craft/n2Efmju5nLM/KUEyMOFIBAAJ
Applying Systems Design
and Domain-Driven Design
What skills do your
APIs need to offer?
Finding APIs through product
and resource boundaries
Domain Driven Design (DDD)
 Mapping domain concepts into software
 Heavy focus on domain expert involvement
 Common vocabulary (“Ubiquitous Language”)
 Boundary-driven (“Bounded Context”)
 Applies learning over time
 Based on Eric Evans' book "Domain Driven
Design”
Domain-Driven Design helps
with identifying context
boundaries for complex APIs
Lack of Modularization = Regret
VS
Function-Based Module-Based
Microservice Architecture
 Microservices are independently deployable,
loosely-coupled components
 Apply bounded context to limit cognitive load
 Benefit from heavy automation (CI/CD)
 Enable replaceability and experimentation
 Encourage composability of the business for
new products
Microservices require a renewed
focus on
systems and API design
Modeling a System
System/Solution
Subsystem Subsystem
Module Module
Module Module
Subsystem Subsystem
Module Module
LEGO as Modular System Design
System
Sub-systems
Modules
LEGO as a System of Systems
System
System
System
System
System
Example:
Marketplace Platform API
List Avail
Inventory
Distributor
Add Product
to Order
Complete
Order
Cancel
Booking
Add Product
to Inventory
Update
Product Qty
Locate
Booking
Redeem
Booking
Point
Of Sale
Remove
Product
Customer
Operator
Operator
Order Mgmt
List Avail
Inventory
Distributor
Add Product
to Order
Complete
Order
Cancel
Booking
Add Product
to Inventory
Update
Product Qty
Locate
Booking
Redeem
Booking
Operator
Point
Of Sale
Remove
Product
Customer
Operator
Inventory Mgmt
Fulfillment
Driving API Design
Each subsystem has an API that
exposes one or more endpoints
Order API
List Avail
Inventory
Distributor
Add Product
to Order
Complete
Order
Cancel
Booking
Add Product
to Inventory
Update
Product Qty
Locate
Booking
Redeem
Booking
Point
Of Sale
Remove
Product
Customer
Operator
Inventory API
Fulfillment API
Operator
Identifying product
opportunities becomes easier
when we have boundaries
around the APIs
Order API
List Avail
Inventory
Distributor
Add Product
to Order
Complete
Order
Cancel
Booking
Add Product
to Inventory
Update
Product Qty
Locate
Booking
Redeem
Booking
Operator
Remove
Product
Inventory API
Fulfillment API
#1 #2
`
Point
Of Sale
For every API, ask:
“What resources will it offer?”
Use domain-driven design to
find business entities, relations,
state transitions, and events
Order API
List Avail
Inventory
Add Product
to Order
Complete
Order
Cancel
Booking
Add Product
to Inventory
Update
Product Qty
Locate
Booking
Redeem
Booking
Remove
Product
Inventory API
Fulfillment API
Order API
Availabilities
Orders
Products
(Inventory)
Bookings
Inventory API
Fulfillment API
Same entity (Products),
Conceptually different to
the API context!
Availabilities
- product
- date(s) avail
- qty avail
Orders
- bookings
- order total
Products
- name
- avail schedule
Bookings
- product
- date(s)
- status
Availabilities
- product
- date(s) avail
- qty avail
availabilityChanged()
Orders
- bookings
- order total
created()
updated()
Products
- name
- avail schedule
created()
removed()
updated()
Bookings
- product
- date(s)
- status
redeemed()
cancelled()
Availabilities
- product
- date(s) avail
- qty avail
availabilityChanged()
Orders
- bookings
- order total
created()
updated()
Products
- name
- avail schedule
created()
removed()
updated()
Bookings
- product
- date(s)
- status
redeemed()
cancelled()
Order API Inventory API
Fulfillment API
Map Resources to the API
API composability using
microservices
Public APIs target durability
Microservice APIs target replaceability
Availabilities
Service
createAvailability()
updateAvailability ()
deleteAvailability ()
…
availabilityChanged(
)
Orders Service
createOrder()
updateOrder ()
deleteOrder ()
…
created()
updated()
Products Service
createProduct()
updateProduct ()
deleteProduct ()
…
created()
removed()
updated()
Bookings Service
lookupBooking()
redeemBooking ()
cancelBooking ()
…
redeemed()
cancelled()
Order API Inventory API
Fulfillment API
Orders HTTP API Inventory HTTP API
Fulfillment HTTP
API
VoiceSkill
API
Product
API
Product
Messaging
…
Microservice
…
API
…
Microservice
…
API
…
Microservice
…API
…
Microservice
…
API
Chatbot
Web+
MobileApp
API
Product
Microservice Architecture
The Composable World of APIs
Offers API
Inventory
API
Bookings
API
Identity API
Accounts
API
Rewards
API
Partners
Internal
Developers
Public App
Developers
Consumers
Third-party
Approved Apps
Summary
 Great API design is critical for product adoption
and long-term API success
 API Design is an architectural concern that
combines business drivers, product design, and
software design
 Systems design and DDD help with designing
long-lasting APIs
 Use microservices where appropriate to increase
composability of your business or product
 Be a storyteller using APIs
Thank you
James Higginbotham
james@launchany.com
@launchany

Applying Domain-Driven Design to APIs and Microservices - Austin API Meetup

Editor's Notes

  • #2 We’re going to talk about how to design LONG-LASTING APIs. The goal is to avoid a redesign not long after your API is deployed. API TRAINING to help coach teams on how to think in APIs and apply the techniques I’ll show you today Across every team and company, I reiterate one common theme…
  • #3 At their core, APIs are contracts for software component interaction. How we design our APIs will drive the level of short and long-term success. As an example, STRIPE…
  • #4 Stripe is well known because they focus on great API design and documentation. But it extends beyond that. They tell a story with their API: “we power commerce for businesses of all sizes” Everything is built around that…
  • #5 Medhi recently tweeted that Stripe maintains 50 (actually now closer to 65) different versions of their API. They OWN VERSIONING, rather than pushing it to the CONSUMER. Event when we, as designers, MISS THE MARK Their API TELLS A STORY…
  • #7 FINTECH is exploding and Capital One is leading the way 3 APIs… Publicly sharing their processes, lessons, and future vision at SXSW Watch the videos
  • #8 Watson offers a variety of services for developing cognitive applications LANGUAGE, SPEECH, VISION, and DATA INSIGHTS
  • #9 Characters, stories, comics, creators, and events
  • #11 Kin Lane has been conducting API workshops at universities by showing how to ACCOMPLISH THINGS Zapier/IFTTT is his model for teaching the use of APIs
  • #12 Ticketmaster demonstrates how skills may vary based on a role or context – we will focus on this kind of API for the purposes of this talk This requires applying proper API design techniques Does your API reflect getting things done, or pushing data around?
  • #13 MOST SIGNIFICANT DESIGN DECISIONS Software design, not ivory tower architects WE ARE ALL software architects – we all make significant design decisions AT SOME POINT in the life cycle
  • #14 Web APIs are an architectural concern, but MORE THAN THAT – PRODUCT AND BUSINESS TODAY IS HTTP, TOMORROW may be something else Use architectural design techniques to drive your API design What is it we are trying to solve and how are we planning to solve it? THAT IS THE PRODUCT SIDE and WHAT IS MOST EXCITING TO ME
  • #15 Since we have to look at APIs as part of (or) a complete product, it requires OUTSIDE-IN design approaches Mike Admundsen wrote about this on a recent API craft google group
  • #16 I want to SHARE what METHODS I have USED to HELP TEAMS DESIGN APIs Product development = opportunity + need + solution Systems design defines how your product is architected API Systems design tells 2 stories: about how your API is architected (internal-facing), and how your API works within other solutions (external-facing)
  • #18 Ecommerce example – what does it take to place an order? These are the skills that our API must offer Essential step #1
  • #19 Next step is finding our APIs, product boundaries, and resource boundaries
  • #20 This is where our agile techniques such as REFACTORING and iterative development
  • #22 <<ADV…>>There are several popular web frameworks that make building a monolithic application easy – almost trivial. These frameworks commonly offer: accelerated development, code generation, open source plugins/extensions, simplified deployment and the ability to scale out by adding more instances as required to support the current load. The problem is that they encourage poor software architecture unless carefully monitored. This leads to a lack of proper modularization...
  • #23 10 years, new frameworks, but they assume a single subsystem – the webapp or “site” They missed the mark for larger applications, trying to avoid SOA This is leading to “MONOLITHIC REGRET” and a lack of modular applications Microservices is becoming a common way to deal with this problem at LARGER SCALES
  • #26 Systems: SOLUTION to PROBLEM(s) Subsystems: BOUNDED CONCERNS Modules: BUILDING BLOCKS for Composition
  • #27 Demonstration of LEGO of how to BREAK a big KIT (problem) into smaller, manageable modules ALIGN OURSELVES based on core competencies
  • #28 Independent systems combined into a larger solution Each built by teams or TEAMS OF TEAMS
  • #29 Constrained on what I can share Extract concepts to demonstrate the process
  • #30 First step – list, understand what the business requirements were, how different parties were to interact with the system
  • #31 Group related activities participant(s) need to perform into subsystems Use the boundaries to determine: - what has already been built in-house - what needs to be built in-house - what can be replaced by COTS, third-party APIs
  • #36 We found 2 stories: a distributor story and an operator story = 2 PRODUCTS Operators vs Distributors drove API DESIGN, DOCS, MARKETING Different vocabularies for distributors and operators
  • #37 Not “what are your endpoints” or “what are your URLs”
  • #38 Discuss aggregates, entities, and value objects. Aggregates become resources, named after the root entity within Goal: Consistent naming that reflects the API’s intended use
  • #42 EVENTS – often MISSED OPPORTUNITY Callbacks change the way developers interact with you API, from POLLING to automatic NOTIFICATION when things change. Allows them to be more reactive to change in your own subsystems
  • #43 [recall early in the talk: when is my product ready to launch?] Our architecture shows us not only what we need to build, but what each party needs to accomplish their goals/solution. This helps us with product roadmaps, scheduling, and other internal aspects of product management.
  • #46 Durability == LONG LASTING Replaceability == AGILITY, EXPERIMENTATION, EVOLUTION
  • #47 HTTP is just a gateway to your underlying subsystems. Systems design help us find those boundaries Domain-driven design help us find our service boundaries Events tie them together