applying domain-driven design to apis and microservices - austin api meetup

50
Applying Domain Driven Design to APIs and Microservices James Higginbotham [email protected] @launchany

Upload: launchany

Post on 15-Apr-2017

351 views

Category:

Software


4 download

TRANSCRIPT

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

Applying Domain Driven Design to APIs and Microservices

James [email protected]

@launchany

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

Great API Design is critical for product adoption and long-term

API success

Page 3: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Page 4: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Page 5: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup

API design also tells a story about your company and your vision of what the world can

become.

Page 6: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Page 7: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Page 8: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Page 9: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup

Your API design defines the capabilities or skills your API

offers to developers

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

Credit: http://kinlane.github.io/university-api-workshop/apis/

Page 11: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Page 12: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup

Architecture is design

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

API Design is an architectural concern that combines business

drivers, product design, and software design

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

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

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

Applying Systems Designand Domain-Driven Design

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

What skills do your APIs need to offer?

Page 17: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Page 18: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup

Finding APIs through product and resource boundaries

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

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”

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

Domain-Driven Design helps with identifying context

boundaries for complex APIs

Page 21: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Page 22: Applying Domain-Driven Design to APIs and Microservices  - Austin API Meetup

Lack of Modularization = Regret

VS

Function-Based Module-Based

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

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

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

Microservices require a renewed focus on

systems and API design

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

Modeling a System

System/Solution

Subsystem Subsystem

Module Module

Module Module

Subsystem SubsystemModule Module

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

LEGO as Modular System Design

System

Sub-systems

Modules

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

LEGO as a System of Systems

System

System

System

SystemSystem

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

Example: Marketplace Platform API

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

List Avail Inventory

DistributorAdd Product

to Order

CompleteOrder

Cancel Booking

Add Product to Inventory

Update Product Qty

LocateBooking

Redeem Booking

PointOf Sale

Remove Product

Customer

Operator

Operator

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

Order Mgmt

List Avail Inventory

DistributorAdd Product

to Order

CompleteOrder

Cancel Booking

Add Product to Inventory

Update Product Qty

LocateBooking

Redeem Booking

Operator

PointOf Sale

Remove Product

Customer

Operator

Inventory Mgmt

Fulfillment

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

Driving API Design

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

Each subsystem has an API that exposes one or more endpoints

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

Order API

List Avail Inventory

DistributorAdd Product

to Order

CompleteOrder

Cancel Booking

Add Product to Inventory

Update Product Qty

LocateBooking

Redeem Booking

PointOf Sale

Remove Product

Customer

Operator

Inventory API

Fulfillment API

Operator

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

Identifying product opportunities becomes easier

when we have boundaries around the APIs

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

Order API

List Avail Inventory

DistributorAdd Product

to Order

CompleteOrder

Cancel Booking

Add Product to Inventory

Update Product Qty

LocateBooking

Redeem Booking

Operator

Remove Product

Inventory API

Fulfillment API

#1 #2`

PointOf Sale

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

For every API, ask: “What resources will it offer?”

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

Use domain-driven design to find business entities, relations,

state transitions, and events

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

Order API

List Avail Inventory

Add Product to Order

CompleteOrder

Cancel Booking

Add Product to Inventory

Update Product Qty

LocateBooking

Redeem Booking

Remove Product

Inventory API

Fulfillment API

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

Order API

Availabilities

Orders

Products(Inventory)

Bookings

Inventory API

Fulfillment API

Same entity (Products), Conceptually different to

the API context!

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

Availabilities- product

- date(s) avail- qty avail

Orders- bookings

- order total

Products- name

- avail schedule

Bookings- product- date(s)- status

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

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

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

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

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

Map Resources to the API

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

API composability using microservices

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

Public APIs target durability

Microservice APIs target replaceability

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

Availabilities Service

createAvailability()updateAvailability ()deleteAvailability ()

…availabilityChanged()

Orders ServicecreateOrder()

updateOrder ()deleteOrder ()

…created()updated()

Products ServicecreateProduct()

updateProduct ()deleteProduct ()

…created()

removed()updated()

Bookings ServicelookupBooking()

redeemBooking ()cancelBooking ()

…redeemed()cancelled()

Order API Inventory API

Fulfillment API

Orders HTTP API Inventory HTTP API

Fulfillment HTTP API

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

Voic

e Sk

ill

API

Prod

uct

API

Prod

uct

Mes

sagi

ng

…Microservice

API

…Microservice

API

…Microservice

…AP

I

…Microservice

APICh

atbo

tW

eb +

M

obile

App

API

Prod

uct

Microservice Architecture

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

The Composable World of APIs

Offers API

Inventory API

Bookings API

Identity API

Accounts API

Rewards API

Partners

InternalDevelopers

Public AppDevelopers

Consumers

Third-partyApproved Apps

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

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

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

Thank you

James [email protected]

@launchany