small medium large xlarge

Domain Modeling Made Functional: Tackle Software Complexity with Domain-Driven Design and F#


Cover image for Domain Modeling Made Functional

Domain Modeling Made Functional

Tackle Software Complexity with Domain-Driven Design and F#


You want increased customer satisfaction, faster development cycles, and less wasted work. Domain-driven design (DDD) combined with functional programming is the innovative combo that will get you there. In this pragmatic, down-to-earth guide, you’ll see how applying the core principles of functional programming can result in software designs that model real-world requirements both elegantly and concisely—often more so than an object-oriented approach. Practical examples in the open-source F# functional language, and examples from familiar business domains, show you how to apply these techniques to build software that is business-focused, flexible, and high quality.

Choose Your Format(s)

  • $24.95 In Stock
    • Beta: What do I get?

  • Ebooks are DRM free.

  • Ebook delivery options.

About this Title

Pages: 290 (est)
Published: 2018-01-10
Release: B6.0 (2018-01-16)
ISBN: 978-1-68050-254-1

Domain-driven design is a well-established approach to designing software that ensures that domain experts and developers work together effectively to create high-quality software. This book is the first to combine DDD with techniques from statically typed functional programming. This book is perfect for newcomers to DDD or functional programming—all the techniques you need will be introduced and explained.

Model a complex domain accurately using the F# type system, creating compilable code that is also readable documentation—ensuring that the code and design never get out of sync. Encode business rules in the design so that you have “compile-time unit tests,” and eliminate many potential bugs by making illegal states unrepresentable. Assemble a series of small, testable functions into a complete use case, and compose these individual scenarios into a large-scale design. Discover why the combination of functional programming and DDD leads naturally to service-oriented and hexagonal architectures. Finally, create a functional domain model that works with traditional databases, NoSQL, and event stores, and safely expose your domain via a website or API.

Solve real problems by focusing on real-world requirements for your software.

What You Need

The code in this book is designed to be run interactively on Windows, Mac and Linux. You will need a recent version of F# (4.0 or greater), and the appropriate .NET runtime for your platform. Full installation instructions for all platforms at

Contents & Extracts

This book is currently in beta, so the contents and extracts will change as the book is developed.

  • Preface
  • Understanding the Domain*
    • Introducing Domain Driven Design
      • The Importance of a Shared Model
      • Understanding the Domain Through Events
      • Partitioning the Domain into Subdomains
      • Creating a Solution Using Bounded Contexts
      • Creating a Common Language
      • Summarizing the Concepts of Domain-Driven Design
      • Wrapping Up
    • Understanding the Domain
      • Interview with a Domain Expert
      • Fighting the Impulse to do Database-Driven Design excerpt
      • Fighting the Impulse to do Class-Driven Design
      • Documenting the Domain
      • Diving Deeper into the Order-Taking Workflow
      • Representing Complexity in Our Domain Model
      • Wrapping Up
      • What’s Next
  • Modeling the Domain
    • Understanding Types
      • Understanding Functions
      • Types and Functions
      • Composition of Types
      • Working with F# Types
      • Building a Domain Model by Composing Types
      • Modeling Optional Values, Errors and Collections
      • Organizing Types in Files and Projects
      • Wrapping Up
    • Domain Modeling with Types
      • Reviewing the Domain Model
      • Seeing Patterns in a Domain Model
      • Modeling Primitive Values
      • Modeling Complex Data excerpt
      • Modeling Processes with Functions
      • A Question of Identity: Value Objects
      • A Question of Identity: Entities
      • Aggregates
      • Putting it All Together
      • Wrapping Up
    • Integrity and Consistency in the Domain
      • Integrity of Primitive Values
      • Units of Measure
      • Enforcing Invariants with the Type System
      • Capturing Business Rules in the Type System
      • Consistency
      • Wrapping Up
    • Modeling Workflows as Pipelines
      • Data Transfer Objects
      • Commands
      • Modeling an Order as a Set of States
      • State Machines
      • Defining Each Stage in the Workflow
      • Are Dependencies Part of the Design?
      • The Complete Pipeline
      • Long Running Workflows
      • Wrapping Up this Chapter
      • What’s Next
  • Implementing the Model
    • Understanding Functions
      • “Functional Programming” Means “Functions Everywhere”
      • Functions are Things excerpt
      • Total Functions
      • Composition
      • Review of F# Syntax
      • Wrapping Up
    • Implementation Part 1: Composing a Pipeline
      • Creating a Domain Object from a DTO
      • Using Function Signatures to Guide the Implementation
      • Composing the Pipeline Steps Together
      • Working with External Services
      • Injecting Dependencies
      • Testing Dependencies
      • The Complete Pipeline
      • Wrapping Up
    • Implementation Part 2: Working with Errors
      • Using the Result Type to Make Errors Explicit
      • Working with Domain Errors
      • Chaining Result-Generating Functions
      • Applying “bind” and “map” to our Pipeline
      • Adapting other kinds of Functions to the Two-Track Model
      • Making Life Easier with Computation Expressions
      • Combining Error Generating Functions in Parallel
      • Monads and Applicatives
      • The Complete Pipeline, Now with Error Handling
      • Wrapping Up
    • Combining Use-Cases into a Functional Architecture
      • Notes
    • Persistence and Serialization
      • Principles of Persistence
      • Command-Query Separation
      • Bounded Contexts Must Own Their Own Data Store
      • Principles of Serialization
      • Translating Domain Types to DTOs
      • Working with Relational Databases
      • The Repository Pattern
      • Persisting to JSON/XML
      • Keeping State Out of Pipelines
      • Keeping State in Memory with Agents
      • Event Sourcing
    • Exposing an API
      • Notes


Scott Wlaschin is an expert on F#, author of the popular F# site, and a board member of the F# Software Foundation. Known for his non-academic approach to functional programming, Scott is a popular speaker and has given talks at NDC, F# Exchange, DDD Europe, and other conferences around the world.