Applying	Domain	Driven	Design	to	
APIs	and	Microservices	
James	Higginbotham	
@launchany
Your	API	tells	a	story	and	
creates	a	conversa3on	between	
you	and	the	world
A	great	API	design	strategy	is	
cri3cal	for	API	product	adop3on	
and	sustainable	applica3on	
development
Your	API	design	is	a	contract	
with	your	API	consumers.	It	is	
“mission	cri3cal”	to	them.
Your	API	design	is	composed	of	
the	capabili3es	(or	“skills”)		
you	offer	to	developers
API	Skills	==	“I	want	to…”
What	skills	do	your		
APIs	need	to	offer?
Outside-In	API	Design	Approach	
Web	
Applica3on	
API	Design	–	“The	Contract”	
Internal	
Applica3on	
API	Consumer	
Mobile	
Applica3on
API	Design	is	an	architectural	
concern	that	combines	business,	
product	design,	and	soKware	
engineering
Lack	of	ModularizaIon	=	Regret	
VS	
Purpose-Based	 Module-Based
High	cohesion		
internally	for		
closely-related	
funcIonality	
Loose	coupling		
externally	across	
modules	without	
internal	details	
High	Cohesion	+	Loose	Coupling
package	 package	
public	
Public	APIs		
encourage	
loose	coupling	
between	modules	
API	
Scoping	rules	
restrict	access	
outside	of	modules	
X
API-Centric	SoPware	Design
Systems	Design	
System	
Subsystem	 Subsystem	
Module	 Module	
Module	 Module	
Subsystem	 Subsystem	
Module	 Module
LEGO	as	Modular	System	Design	
System	
Subsystems	
Modules
API	
API	
API	
System/SoluIon	
Subsystem	 Subsystem	
Subsystem	
Module	 Module	
Module	 Module	
Module	 Module	
Module	 Module	
Module	 Module	
Module	 Module	
Module	 Module	
Module	 Module
Domain-Driven	Design	helps	
with	iden3fying	context	
boundaries	for	complex	APIs
Domain	Driven	Design	(DDD)	
u  Maps	domain	concepts	into	soPware	
u  Heavy	domain	expert	involvement	
u  Common	vocabulary	(“Ubiquitous	Language”)	
u  Boundary-driven	(“Bounded	Context”)	
u  Apply	learning	over	Ime
“I	need	to	mul3ply	two	numbers	
together.	So,	I	am	building	
a	microservice	architecture.”	
-	almost	everyone	today
Microservice	Architecture	
u  Loosely-coupled,	service-oriented	architecture	
u  Apply	bounded	context	to	limit	cogniIve	load	
u  Independently	deployable	via	automaIon	
u  Enable	replaceability	and	experimentaIon	
u  Encourage	composability	of	the	business	
u  Best	for	large	teams,	or	co-located	disparate	data
Applying	Systems	Design	
and	Domain-Driven	Design	
to	find	API	boundaries		
and	resources
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
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
Iden3fying	product	opportuni3es	
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	en33es,	rela3ons,	
state	transi3ons,	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	
Product	
AvailabiliIes	
Orders	
Product	
Inventory	
Bookings	
Inventory	API	
Fulfillment	API	
Same	enIty	(Products),		
Conceptually	different	to		
the	API	context!
Availabili3es	
-	product	
-	date(s)	avail	
-	qty	avail	
	
Orders	
-	bookings	
-	order	total	
Products	
-	name	
-	avail	schedule	
Bookings	
-	product	
-	date(s)	
-	status
Availabili3es	
-	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()
Availabili3es	
-	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	
	through	external	contracts	
	
Microservice	APIs	target	
evoluIon	through	
experimentaIon	Photo	Credit:	h,ps://www.flickr.com/photos/libel_vox
Availabili3es	Service	
	
Orders	Service	
Products	Service	
Bookings	Service	
Orders	HTTP	API	
Inventory	HTTP	API	
Fulfillment	HTTP	API
Availabili3es	Service	
	
Orders	Service	
Products	Service	
Bookings	Service	
Orders	HTTP	API	
Inventory	HTTP	API	
Fulfillment	HTTP	API	
Payment	Service	
	
Refund	Service
Alexa		
Voice	Skill	
API	
Gateway	
API	
Gateway	
Messaging	
…	
Microservice	
…	
API	
…	
Microservice	
…	
API	
…	
Microservice	
…	
API	
…	
Microservice	
…	
API	
Slack		
Chatbot	
Web	+	
Mobile	App	
API	
Gateway	
Microservice	Architecture
MigraIng	to	Microservices	
1.  Use	API	Facades	to	define	clear	interfaces	
2.  Separate	complex	concerns	into	separate	
services	
3.  Use	Service	Object	Paeern	to	decompose	
4.  Build	an	automated	deployment	pipeline	
5.  Migrate	service	objects	to	microservices
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
Thank	you	
James	Higginbotham	
@launchany	
hep://bit.ly/api-skills

API:World 2016 - Applying Domain Driven Design to APIs and Microservices