SlideShare a Scribd company logo
APIS WITH BOUNDED
CONTEXTS
Modelling APIs with Domain-Driven Design
José Haro Peralta
Consultant and instructor
Founder of microapis.io
API World Conference
28 Oct – 3 Nov 2022
@microapisio
@JoseHaroPeralta
$ whoami
• I’m Jose
• Consultant, author, instructor
• Author of Microservices and APIs
• Founder of microapis.io
@JoseHaroPeralta
@microapisio
35% discount code: ctwapiworld22
microapis.io
39% discount code: ctwapi21
One-click API mock servers
@JoseHaroPeralta
@microapisio
Connect with me!
 Twitter: @JoseHaroPeralta
 GitHub: @abunuwas
 Medium: @joseharoperalta /@python-geek
 LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/
Agenda
 Complexity of creating good API design
 More in particular, good REST API design
 How domain-driven design helps to design better APIs
 Special case of data-driven applications
Ubiquitous APIs
• Using domain-driven design to align with the business helps us
create better APIs
• Think about processes and flows instead of endpoints and
HTTP status codes
• How leveraging API design principles such as uniform interface
helps us create ubiquitous APIs
• Leveraging HTTP semantics helps us create ubiquitous APIs
Reality is more complex than textbook cases
• Many projects start out as an experiment and/or PoC and then there’s pressure to
build the production application quickly (the business case often depends on the
speed of delivery)
• In reality, we often figure out what we’re doing on the go (the domain and the
subdomains become clear as we progress in our work)
• The business often lacks terminology to refer to their own processes and flows and to
their own “entities”
• Data-driven applications are notoriously hard to model (everything is “data”)
APIs for data-driven applications anti-patterns
• API conceived as data gateways
• Lack of API design and validation
• Lacking notion of operations
• Oversimplification through CRUD (CRUDified APIs)
• God models
• Cluttered endpoints
• Lacking HTTP semantics
• Breaking uniform interface
Build a sales forecasting
application
• Digital transformation project in major international retail org
• Automate sales forecasting
• From two forecasts a year to rolling forecast
• More accurate forecast
• Being able to model multiple scenarios
• Keep track of historical forecasts and compare
Starting with an
experiment
• We started with a small experiment
• Early Machine Learning iterations proved successful
Building a PoC
• Built a quick UI using Dash (Python library)
• Weekly iterations
PoC validated – project kicks off
Split UI and backend
1
Expose backend API
2
Operate at scale
3
Project kicks off – new architecture
API design challenges
• It becomes clear that the business lacks terminology to refer to their own processes
and flows, and to their “entities”
• Different countries use different processes and flows
• We think of states instead of different entities and we have a “God model”
API design challenges
• We drag bad models from the PoC
• Cluttered endpoints due to over-reuse
• Very difficult to continue extending the API
• 2 languages: business and data science
APIs with Bounded Contexts: Modelling Apis with Domain-Driven Design
God models: using states instead of entities
Bad models
Cluttered endpoints
• POST /forecast => retrieve raw forecast
• POST /forecast + adjustments => create scenario
• POST /forecast + adjustments + new stores => create new store forecast
• PUT /forecast/{forecast_id} => create candidate
• PUT /forecast/{forecast_id} => create submission
From states to entities
Raw forecast
Scenario
Candidate
Submission
New store
forecast
Modeling operations
• Stop thinking in terms of URLs and HTTP methods
• Start thinking in terms of operations
• Decouple your backend data model from your API models
• Leverage HTTP semantics
• Enforce uniform interface
Start with operations, processes, and flows
• Retrieve raw forecast
• Create and update scenarios
• Create and update candidate
• Create submission
• Create forecasts and scenarios for new stores
Use meaningful resource endpoints and
leverage HTTP semantics
Conclusions
• Changing the API is risky – can break integrations => address design issues early
• Don’t think in terms of URLs and HTTP methods => think in terms of operations, processes, and
flows
• Don’t crudify your APIs – if an operation isn’t needed, don’t add it
• Flexible models are bad => create discrete models for each entity
• Clarity over reusability => don’t reuse endpoints and models
Thanks for listening!
Twitter: @JoseHaroPeralta
GitHub: @abunuwas
Medium: @joseharoperalta /@python-geek
LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/
35% discount code: ctwapiworld22
ADDITIONAL READINGS
• Microservice APIs by J. Haro (mng.bz/nz48)
• “Building and deploying reliable APIs with FastAPI” by J. Haro
(https://www.twitch.tv/videos/1088283640)
• Documentation-driven development for APIs by J. Haro
(https://link.medium.com/m2A3rOxUfib)
• “Developing API clients doesn’t need to be a pain” by J. Haro
(https://link.medium.com/0B9vt7DUfib)
• “How bad models ruin an API” by J. Haro (https://microapis.io/blog/how-bad-models-
ruin-an-api)
• “API-first development maturity framework” by J. Haro (https://microapis.io/blog/api-
development-maturity)
ADDITIONAL READINGS
• “Design patterns for modern web APIs” by D. Luecke
(https://blog.feathersjs.com/design-patterns-for-modern-web-apis-1f046635215)
• The design of web APIs by A Lauret (https://www.manning.com/books/the-design-of-
web-apis)
• Designing APIs with Swagger and OpenAPI by J. S. Ponelat and L. L. Rosenstock
(https://www.manning.com/books/designing-apis-with-swagger-and-openapi)
• API Design Patterns by JJ Geewax (https://www.manning.com/books/api-design-
patterns)
• Principle of Web API Design by J. Higginbotham
(https://www.pearson.com/store/p/principles-of-web-api-design-delivering-value-
with-apis-and-microservices/P200000007278/9780137355631)

More Related Content

ODP
Monitoring via Datadog
PPT
Introduction au Domain Driven Design
PDF
Microsoft Azure Fundamentals
PDF
Azure Application insights - An Introduction
PDF
ELB와 EBS의 아키텍터로 생각해보는 사용상 주의할 점들
PPTX
Microsoft Threat Protection
PDF
Monitor every app, in every stage, with free and open Elastic APM
PDF
The Beginner’s Guide To Spring Cloud
Monitoring via Datadog
Introduction au Domain Driven Design
Microsoft Azure Fundamentals
Azure Application insights - An Introduction
ELB와 EBS의 아키텍터로 생각해보는 사용상 주의할 점들
Microsoft Threat Protection
Monitor every app, in every stage, with free and open Elastic APM
The Beginner’s Guide To Spring Cloud

What's hot (20)

PDF
Event Driven-Architecture from a Scalability perspective
PDF
TOP SAILPOINT INTERVIEW QUESTION
PDF
[오픈소스컨설팅]Scouter 설치 및 사용가이드(JBoss)
PDF
Oracle CodeOne 2019: Descending the Testing Pyramid: Effective Testing Strate...
PDF
초보 개발자도 바로 따라할 수 있는 AWS 미디어 서비스를 이용한 Live/VOD 서비스 구축 – 현륜식 AWS 솔루션즈 아키텍트:: A...
PDF
Event Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
PPTX
Understanding Zero Trust Security for IBM i
PDF
Threat Hunting with Splunk Hands-on
PDF
Open API and API Management - Introduction and Comparison of Products: TIBCO ...
PPTX
Application Architecture
PDF
Infrastructure as Code
PPTX
Microservices With Istio Service Mesh
PPSX
Microservices Docker Kubernetes Istio Kanban DevOps SRE
PDF
Kafka for Real-Time Replication between Edge and Hybrid Cloud
PDF
Microsoft Cloud's Front Door: Building a Global API
PPTX
CQRS & EVS with MongoDb
PDF
Building Event Driven (Micro)services with Apache Kafka
PDF
Designing APIs with OpenAPI Spec
PPTX
Azure Identity and access management
PPTX
Event Driven-Architecture from a Scalability perspective
TOP SAILPOINT INTERVIEW QUESTION
[오픈소스컨설팅]Scouter 설치 및 사용가이드(JBoss)
Oracle CodeOne 2019: Descending the Testing Pyramid: Effective Testing Strate...
초보 개발자도 바로 따라할 수 있는 AWS 미디어 서비스를 이용한 Live/VOD 서비스 구축 – 현륜식 AWS 솔루션즈 아키텍트:: A...
Event Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
Understanding Zero Trust Security for IBM i
Threat Hunting with Splunk Hands-on
Open API and API Management - Introduction and Comparison of Products: TIBCO ...
Application Architecture
Infrastructure as Code
Microservices With Istio Service Mesh
Microservices Docker Kubernetes Istio Kanban DevOps SRE
Kafka for Real-Time Replication between Edge and Hybrid Cloud
Microsoft Cloud's Front Door: Building a Global API
CQRS & EVS with MongoDb
Building Event Driven (Micro)services with Apache Kafka
Designing APIs with OpenAPI Spec
Azure Identity and access management
Ad

Similar to APIs with Bounded Contexts: Modelling Apis with Domain-Driven Design (20)

PDF
INTERFACE by apidays 2023 - APIs with bounded contexts, Jose Haro Peralta, mi...
PPTX
APIs with Bounded Contexts: Modeling APIs with Domain-Driven Design
PDF
O'Reilly SACon San Jose, CA - 2019 - API design tutorial
PDF
Mind The Gap - Mapping a domain model to a RESTful API - OReilly SACon 2018, ...
PDF
Design & Deploy a data-driven Web API in 2 hours
PDF
O reilly sacon2018nyc - restful api design - master - v1.0
PDF
Dependency Down, Flexibility Up – The Benefits of API-First Development
PPTX
Refining Your API Design - Architecture and Modeling Learning Event
PDF
apidays Paris 2022 - Generating APIs from business models, Frederic Fontanet,...
PPTX
INTERFACE, by apidays - Design for your API customers with APIOps Cycles by ...
PPTX
apidays LIVE Paris 2021 - Generating OpenAPIs from business models by Frederi...
PDF
"API Design: From User Need to Finished Spec" by Andrew Jordan, ex-Product @T...
PPTX
Navigating the Post-OpenAPI Era with Innovative API Design Frameworks - Danie...
PPTX
Designing APIs and Microservices Using Domain-Driven Design
PDF
apidays Australia 2022 - API design challenges and making APIs your common la...
PPTX
Applying Domain-Driven Design to APIs and Microservices - Austin API Meetup
PDF
APIs are for People Too
PDF
MuleSoft Surat Meetup#39 - Pragmatic API Led Connectivity
PDF
Api design best practice
PPTX
API economy
 
INTERFACE by apidays 2023 - APIs with bounded contexts, Jose Haro Peralta, mi...
APIs with Bounded Contexts: Modeling APIs with Domain-Driven Design
O'Reilly SACon San Jose, CA - 2019 - API design tutorial
Mind The Gap - Mapping a domain model to a RESTful API - OReilly SACon 2018, ...
Design & Deploy a data-driven Web API in 2 hours
O reilly sacon2018nyc - restful api design - master - v1.0
Dependency Down, Flexibility Up – The Benefits of API-First Development
Refining Your API Design - Architecture and Modeling Learning Event
apidays Paris 2022 - Generating APIs from business models, Frederic Fontanet,...
INTERFACE, by apidays - Design for your API customers with APIOps Cycles by ...
apidays LIVE Paris 2021 - Generating OpenAPIs from business models by Frederi...
"API Design: From User Need to Finished Spec" by Andrew Jordan, ex-Product @T...
Navigating the Post-OpenAPI Era with Innovative API Design Frameworks - Danie...
Designing APIs and Microservices Using Domain-Driven Design
apidays Australia 2022 - API design challenges and making APIs your common la...
Applying Domain-Driven Design to APIs and Microservices - Austin API Meetup
APIs are for People Too
MuleSoft Surat Meetup#39 - Pragmatic API Led Connectivity
Api design best practice
API economy
 
Ad

More from José Haro Peralta (7)

PPTX
API Security Fundamentals
PPTX
Pure APIs: Development workflows for successful API integrations
PPTX
Delivering successful API integrations with documentation-driven development
PPTX
Documentation-driven development for Python web APIs v2
PPTX
Documentation-driven development for Python web APIs
PPTX
API Conference 2021
PPTX
PyBCN 2020
API Security Fundamentals
Pure APIs: Development workflows for successful API integrations
Delivering successful API integrations with documentation-driven development
Documentation-driven development for Python web APIs v2
Documentation-driven development for Python web APIs
API Conference 2021
PyBCN 2020

Recently uploaded (20)

PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
medical staffing services at VALiNTRY
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
System and Network Administraation Chapter 3
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Nekopoi APK 2025 free lastest update
PDF
Digital Strategies for Manufacturing Companies
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPT
Introduction Database Management System for Course Database
Navsoft: AI-Powered Business Solutions & Custom Software Development
medical staffing services at VALiNTRY
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
System and Network Administraation Chapter 3
How to Migrate SBCGlobal Email to Yahoo Easily
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Design an Analysis of Algorithms II-SECS-1021-03
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Odoo Companies in India – Driving Business Transformation.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Which alternative to Crystal Reports is best for small or large businesses.pdf
Design an Analysis of Algorithms I-SECS-1021-03
Nekopoi APK 2025 free lastest update
Digital Strategies for Manufacturing Companies
Softaken Excel to vCard Converter Software.pdf
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Introduction Database Management System for Course Database

APIs with Bounded Contexts: Modelling Apis with Domain-Driven Design

  • 1. APIS WITH BOUNDED CONTEXTS Modelling APIs with Domain-Driven Design José Haro Peralta Consultant and instructor Founder of microapis.io API World Conference 28 Oct – 3 Nov 2022 @microapisio @JoseHaroPeralta
  • 2. $ whoami • I’m Jose • Consultant, author, instructor • Author of Microservices and APIs • Founder of microapis.io @JoseHaroPeralta @microapisio 35% discount code: ctwapiworld22
  • 3. microapis.io 39% discount code: ctwapi21 One-click API mock servers @JoseHaroPeralta @microapisio
  • 4. Connect with me!  Twitter: @JoseHaroPeralta  GitHub: @abunuwas  Medium: @joseharoperalta /@python-geek  LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/
  • 5. Agenda  Complexity of creating good API design  More in particular, good REST API design  How domain-driven design helps to design better APIs  Special case of data-driven applications
  • 6. Ubiquitous APIs • Using domain-driven design to align with the business helps us create better APIs • Think about processes and flows instead of endpoints and HTTP status codes • How leveraging API design principles such as uniform interface helps us create ubiquitous APIs • Leveraging HTTP semantics helps us create ubiquitous APIs
  • 7. Reality is more complex than textbook cases • Many projects start out as an experiment and/or PoC and then there’s pressure to build the production application quickly (the business case often depends on the speed of delivery) • In reality, we often figure out what we’re doing on the go (the domain and the subdomains become clear as we progress in our work) • The business often lacks terminology to refer to their own processes and flows and to their own “entities” • Data-driven applications are notoriously hard to model (everything is “data”)
  • 8. APIs for data-driven applications anti-patterns • API conceived as data gateways • Lack of API design and validation • Lacking notion of operations • Oversimplification through CRUD (CRUDified APIs) • God models • Cluttered endpoints • Lacking HTTP semantics • Breaking uniform interface
  • 9. Build a sales forecasting application • Digital transformation project in major international retail org • Automate sales forecasting • From two forecasts a year to rolling forecast • More accurate forecast • Being able to model multiple scenarios • Keep track of historical forecasts and compare
  • 10. Starting with an experiment • We started with a small experiment • Early Machine Learning iterations proved successful
  • 11. Building a PoC • Built a quick UI using Dash (Python library) • Weekly iterations
  • 12. PoC validated – project kicks off Split UI and backend 1 Expose backend API 2 Operate at scale 3
  • 13. Project kicks off – new architecture
  • 14. API design challenges • It becomes clear that the business lacks terminology to refer to their own processes and flows, and to their “entities” • Different countries use different processes and flows • We think of states instead of different entities and we have a “God model”
  • 15. API design challenges • We drag bad models from the PoC • Cluttered endpoints due to over-reuse • Very difficult to continue extending the API • 2 languages: business and data science
  • 17. God models: using states instead of entities
  • 19. Cluttered endpoints • POST /forecast => retrieve raw forecast • POST /forecast + adjustments => create scenario • POST /forecast + adjustments + new stores => create new store forecast • PUT /forecast/{forecast_id} => create candidate • PUT /forecast/{forecast_id} => create submission
  • 20. From states to entities Raw forecast Scenario Candidate Submission New store forecast
  • 21. Modeling operations • Stop thinking in terms of URLs and HTTP methods • Start thinking in terms of operations • Decouple your backend data model from your API models • Leverage HTTP semantics • Enforce uniform interface
  • 22. Start with operations, processes, and flows • Retrieve raw forecast • Create and update scenarios • Create and update candidate • Create submission • Create forecasts and scenarios for new stores
  • 23. Use meaningful resource endpoints and leverage HTTP semantics
  • 24. Conclusions • Changing the API is risky – can break integrations => address design issues early • Don’t think in terms of URLs and HTTP methods => think in terms of operations, processes, and flows • Don’t crudify your APIs – if an operation isn’t needed, don’t add it • Flexible models are bad => create discrete models for each entity • Clarity over reusability => don’t reuse endpoints and models
  • 25. Thanks for listening! Twitter: @JoseHaroPeralta GitHub: @abunuwas Medium: @joseharoperalta /@python-geek LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/ 35% discount code: ctwapiworld22
  • 26. ADDITIONAL READINGS • Microservice APIs by J. Haro (mng.bz/nz48) • “Building and deploying reliable APIs with FastAPI” by J. Haro (https://www.twitch.tv/videos/1088283640) • Documentation-driven development for APIs by J. Haro (https://link.medium.com/m2A3rOxUfib) • “Developing API clients doesn’t need to be a pain” by J. Haro (https://link.medium.com/0B9vt7DUfib) • “How bad models ruin an API” by J. Haro (https://microapis.io/blog/how-bad-models- ruin-an-api) • “API-first development maturity framework” by J. Haro (https://microapis.io/blog/api- development-maturity)
  • 27. ADDITIONAL READINGS • “Design patterns for modern web APIs” by D. Luecke (https://blog.feathersjs.com/design-patterns-for-modern-web-apis-1f046635215) • The design of web APIs by A Lauret (https://www.manning.com/books/the-design-of- web-apis) • Designing APIs with Swagger and OpenAPI by J. S. Ponelat and L. L. Rosenstock (https://www.manning.com/books/designing-apis-with-swagger-and-openapi) • API Design Patterns by JJ Geewax (https://www.manning.com/books/api-design- patterns) • Principle of Web API Design by J. Higginbotham (https://www.pearson.com/store/p/principles-of-web-api-design-delivering-value- with-apis-and-microservices/P200000007278/9780137355631)