Jump to ratings and reviews
Rate this book

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

Rate this book
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. 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 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 fsharp.org.

312 pages, Paperback

Published March 6, 2018

Loading interface...
Loading interface...

About the author

Scott Wlaschin

3 books18 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
364 (59%)
4 stars
204 (33%)
3 stars
36 (5%)
2 stars
3 (<1%)
1 star
4 (<1%)
Displaying 1 - 30 of 78 reviews
Profile Image for Mark Seemann.
Author 4 books460 followers
November 22, 2018
If you'd like to understand why F# (or statically typed functional programming in general) is useful for everyday 'enterprise' development, then this is the book for you.

You don't have to know F# already. While this isn't an introduction to the F# programming language as such, Scott gives you enough of an introduction that you'll be able to understand what's going on. Instead of using half the book to introduce the language, he shows you just enough, and then he keeps the example code in the book simple. Keeping code simple is good advice anyway, so don't worry that he's cheating. (I have to admit that I write the above paragraph based on my best-effort guess at how easy it is to understand the book if you've never seen F# before; I've been writing F# code for years.)

It's clear throughout the book that Scott has decades of experience with programming. Not only does he address various concerns that you, the reader, could have, but he also shows how to design in a style that will be able to deal with changing requirements, and so on.

To be clear, this isn't a book for everyone. The book starts with an introduction to Domain-Driven Design (DDD) which, I suppose, is useful if you know little about the subject. Everything in that first part of the book is right and proper, but I didn't learn anything that I didn't already know.

I wholeheartedly recommend this book to people who are new to either F#, statically typed functional programming, or DDD. If you've already had more than fleeting encounters with these topics, however, you're unlikely to learn much. It's a beginners' book, although, paradoxically, it's aimed at developers with some years of 'enterprise' development experience.
Profile Image for Sebastian Gebski.
1,077 reviews1,104 followers
August 11, 2017
Based on Beta 1.0 - 2 final chapters still missing.

PragProg doesn't disappoint, but as I've never read any decent book on functional modeling, my initial enthusiasm was rather limited. Additionally, I'm not really keen on F# (as a language) - its OCaml inspiration doesn't impress me, I generally try to avoid F-OO hybrids.

And then, enters Scott Wlaschin. Needless to say, he's not an anonymous person (quite far from that - https://fsharpforfunandprofit.com/), but still - this guy has just accomplished impossible - he has written absolutely fabulous book on Functional Modeling!

Book is very practical - how to compose functionality, how to build models, how to map between models & DTOs, how to compose logic, how the critical DDD concepts (like bounded contexts or aggregates) map to FP, how to deal with error handling.

This is NOT a hardcore FP book - it describes some critical concepts like binding or mapping, there's even a simplified description of a monad, but that's all. Don't expect functors or free monads - Scott doesn't try describing all functional composition patterns. I don't find it a problem - it makes book very approachable & easy to get through. Even at Beta stage, it's a pleasure to read.

Highly recommended if you're into both: DDD & FP.
Profile Image for apollojet.
77 reviews17 followers
February 25, 2019
Ok, so there's one were this girl — I knew she have a husband, but also I knew she wasn't fond of the sucker. She was kinda chubby but qute; and also that was the kind of chubby that makes one's breast grow along with the fat percentage. So she invited me home and we fucked. Several times. And it was fine. But it seemed to me like the fact that it happened mattered for here more than enjoyment or our friendship itself.

Now I know how girls feel when guy immediately starts to dress up after he came.
And you can know the feeling too if you'd read the book.

It's not about F# per se, although it can be used as introduction to language. It's not about developing process in the language — it's just a guy sharing his view of solving problems with software. It's not bad, nor great — it just exists.

And you wouldn't remember it after you bring home another book tomorrow.
Profile Image for Júlia Birkett.
4 reviews3 followers
October 1, 2021
It's really impressive how Domain-Driven Design matches Functional Programming, especially with a typed language as F#. I used to think that DDD made more sense to be applied with OOP, but now I think the opposite.
The book is super easy to read. It contains lots of practical examples using different workflows of a hypothetical (but realistic) domain. It gives you a good sense of how it would be to apply DDD in a real application by covering use cases from the user input until storing them in a database.
One of my favourites about DDD!
Profile Image for Sergey Shishkin.
159 reviews45 followers
March 17, 2018
That's a great book on software design which I would recommend to any developer, no matter of programming language preferences. Scott has a rare ability to explain complex stuff in approachable way through analogies and examples.

I found some code samples quite trivial and mundane for a book, thus 4 stars.
Profile Image for Adrian.
149 reviews22 followers
May 8, 2021
In just a mere 260 pages Scott does a terrific job implementing a real life order processing system in a DDD way starting from requirements gathering , implementation and even further development , explaining along the way DDD concepts (domains, bounded contexts , adapters, side effects) as well as functional programming with F# (including functors , applicatives , monads ) .

While the code snippets and the explanations are great what makes this book shine are the drawings !
Never have i seen so many abstract concepts that are usually hard to grasp so intuitively depicted and explained as in this book !

Must read for anyone interested in DDD , functional programming , Fsharp and designing better and bug-free systems in general !
This entire review has been hidden because of spoilers.
Profile Image for Pepijn Looije.
4 reviews
December 28, 2020
Even without exposure to F#, the code examples are easy to follow. Trivially translatable to Scala, and even to Clojure with a bit of imagination. I constantly refer to this book on my day job (at a big fintech company).
4 reviews
April 19, 2020
I wish I had this book 5 years ago when functional paradigm and F# became part of what I do.

Even though we are all introduced to functional principles in school (without calling it functional, we just called it math) and later (I'm sure some even earlier) in Excel, it is not easy to isolate the afterwards acquired procedural and object oriented thinking. At that moment one has to reserve an innocent place in one's brain to fully embrace the functional paradigm without carrying the old habits along.

If I was reading this book then, with my mind as open as I now recommend to others, not only I would be impressed, I would be put on a good path right away. I would say that this book may be a good entry point to DDD as the context is practical and the F# type system is very fitting for the job.

Be aware that the content of this book may influence your take on thinking about systems, modelling, designing your applications and that may lead to some friction with other fellow developers that may lack the context you just gained.

The book deserves more in terms of formatting. E.g. pictures and tables should have titles, descriptions. The Pragmatic Programmers series suffers in that regard in general, but the contents compensated for that well enough.
Profile Image for Gregor Riegler.
7 reviews2 followers
June 16, 2020
This Book explains the thought process of Software Design using the Functional Paradigm very well.
It's not about the language F#, it's about the paradigm. I do not use F#, nor am i'm planning to.
Still, the book had a lot of value to me.

A key learning is how to take advantage of Types to achieve a better Domain Model.
For me, a OO Guy digging into FP, it was a mind opener.
It teached me how to think in workflows, how to compose and streamline testable functions, how to inject dependencies using partial application, and how to achieve a great result even without using a single monad.

Great Book.
Profile Image for Jo.
37 reviews9 followers
April 4, 2018
Brilliant introduction to Domain-Driven Design, designing with types in F# and "railway-oriented programming".

If you have an interest in any or all of these topics, this book takes an entire feature, from discussing with business stakeholders over designing your code purely on a type level to implementing the actual business logic in a clear cohesive story. It even touches on async/error handling, something a lot of introductory material is very handwavey about and shows how to tackle these concerns in a more functional way.

Highly recommend!
Profile Image for Torben Koch.
27 reviews5 followers
August 7, 2024
Scott made a book by basically distilling, rewriting and ordering a lot of the material on his website. And he did good!

There is a fine introduction to DDD and a lot of neat tricks on how to do it in F#.

Downloading the accompanying code will probably make a dent in your admiration for Scott, though. Functional programmers are seemingly in general lazy people and consistently forget the WORM - Write Once, Read Many - aspect of programming.
Profile Image for Ian Tuomi.
14 reviews4 followers
September 16, 2020
I got a lot out of the first half of the book where the essence of ddd is distilled very cleanly from a functional point of view. I consider many of these viewpoints as close to canon as it gets in software development. Outstanding 5/5

The second half was a mix of strict functional programming strategies like making pure pipelines by composing meticulously typed function inputs and outputs to match each other (I am not a fan of this approach. While satisfying and beautiful, I find it difficult to read, write, and refactor in practice, with no clear benefit. Perhaps I will “see the light” some day :) ) and F# -specific implementation details like serializing Json. There were some gems here and there, but i found myself skimming. I should note that this may be due to me picking up a F# book as a non-F# programmer.

All in all, this is one of the more important books I have read about programming, and recommend just about everyone working on anything related to software to read the first half. Call it “DDD: The Good Parts”
Profile Image for Marcin.
88 reviews44 followers
March 4, 2019
This is a fantastic introduction to both DDD and Functional Programming in a very accessible book. Being grounded in a very concrete and coherent example it's really easy to relate to the ideas presented in the book.
If there is anything I felt lacking from the book, it would be a little more examples of tests and driving implementation with tests alongside driving it with the type system.
Profile Image for Yannick Grenzinger.
55 reviews5 followers
April 6, 2020
Surely one of the best book how to implement the tactical part of DDD in a functional way.
Totally practical, avoiding Category Theory, and giving a lot of knowledge about how tu use functional programming and types to implement a very robust domain.
November 6, 2020
I think it was clear, solid, and well thought out. I learned a model of organizing software architecture, using types as state machines, and allowing them to be driven from your domain and those types driving your computation.
28 reviews3 followers
February 8, 2020
Awesome book for anyone interested in domain modelling!
Profile Image for Jon.
174 reviews7 followers
February 13, 2020
Great read on how to architect your code and make your code easy to understand, use, and change all while make it hard to introduce bugs.
Profile Image for Danien.
44 reviews
April 15, 2018
This is an introductory book and does not cover more advanced functional programming topics, nor does it cover Domain-driven Design (DDD) in detail (see Eric Evans' Domain-Driven Design: Tackling Complexity in the Heart of Software and Vaughn Vernon's Implementing Domain-Driven Design), but it does a good job of explaining how functional programming is a great fit for DDD with clear use of examples.

The author does a good job of starting with simple but naive approaches to software design problems, then explaining the issues they are susceptible to. He follows these with better functional designs and explains the trade-offs. Throughout the book, he uses a coherent example with enough scope to demonstrate common software design problems, instead of jumping around different unrelated examples as other books sometimes do. This helps the reader to see how all the solutions fit together and how they affect one another, with each chapter refining the reader's understanding of the problems and the solutions.

More detailed information and advanced topics can be found at the author's website F# for Fun and Profit, so if you've already covered that, the material in this book presents a more structured approach to that material.

The book is a bit short and I would have liked for it to cover more of the material from the website with the same style and structure in the book with clear examples.
Profile Image for Bugzmanov.
219 reviews65 followers
May 29, 2021
It is a good intro book on doing DDD functional way. To a degree, it's covering the same topic as "Functional and Reactive Domain Modeling" by Debasish Ghosh. But it's significantly shorter and with more evident emphasis on types driven development.
While Ghosh's book is about "i learned about FP, now I want to understand how to write business applications in this style", this one is more about "I know how to do DDD, how can I do it in fp style? But please no category theory this time"

It's a short and easy read, because of limited scope (compared to "Functional and Reactive Domain Modeling") it actually drives points home and makes it clear and concise.
No previous exposure to F# required. The knowledge of how to read F# will come up as a bonus after reading this one.
Highly recommended.
Profile Image for Tomi Turtiainen.
18 reviews
May 20, 2019
This book is just great! It gives a great introduction to DDD and then moves on to show how you can do domain modeling with functional programming. Although the examples are in F#, the book focuses more on explaining and showing functional programming concepts you can use to tackle complexity. I can highly recommend this to anyone who is interested in doing functional programming in complex domains.
Profile Image for Micah.
32 reviews3 followers
May 14, 2021
A solid introduction to functional programming, but not without flaws

In this book, Scott Wlaschin walks us through an imaginary software design project and demonstrates how we can apply functional programming paradigms, as well as the particular capabilities of the F# programming language, to tackling large application development through domain-driven design (DDD).

Some highlights of the book that felt particularly important to me:

* Wlaschin lays out the fundamentals of Domain-Driven Development, including:

- Domains: Areas of knowledge associate with a problem (e.g., "Billing", "Shipping", or "Intake")
- Domain Model: Simplifications that represent a domain to stakeholders
- The Ubiquitous Language: A set of concepts and vocabulary associated with the domain and shared by both team members and the source code
- Bounded Context: A subsection in the solution space with clear boundaries from other subsystems. Subsystems have their own concepts and vocabulary - dialects of the Ubiquitous Language.
- Events: Records of something that has happened in the system
- Commands: A request for something to happen, triggered by a person or event.

* We learn about how events and commands can be used to connect different bounded contexts, allowing them to work together harmoniously while remaining fundamentally decoupled.

Key points here were that each of our bounded contexts need to be able to receive Data Transfer Objects (DTOs), picking up where other bounded contexts have left off. DTOs are received and pass through input and output gates, for validation/sanitization and serialization, respectively. Everything inside the bounded context can be trusted, everything outside must be treated with care - assume nothing, and we avoid much unnecessary coupling.

* Wlaschin introduces the idea of Onion Architecture

The basic concept here is that you keep your domain code stateless and pure, while positioning Async/IO processes (APIs, etc.) on the edges. How well this pattern holds up in practice is debatable, but it is a good ideal.

* We learn about a variety of functional programming patterns, and their application in F#

I won't go too deep here, but did learn a lot about a maximalist functional approach to building pipelines and adapting functions to be able interlink with other functions in the pipeline and pass on their errors as necessary.

I ultimately thought that pipelines are very cool when feasible, but was not convinced that some of the gymnastics that Wlaschin had us go through to achieve clean pipelines were necessarily worth it, or sufficiently maintainable to justify the overhead.

* Wlaschin argues - quite successfully - that types can largely replace documentation

One very powerful idea in this book, and demonstrated in F#, is that code can be demonstrably correct. Throughout the book, Wlaschin emphasizes patterns that make it literally impossible to introduce certain errors. Practiced with discipline, this style of coding could eliminate the need for some classes of tests.

Summing up:

I felt like the book got weaker as it went along, both because Wlaschin tried to accomplish too much in too short a book, often hand-waving advanced concepts, while perhaps spending too much time on trivial concepts and code examples.

I also felt like F# was both the strength and Achilles heel of this book. Because Wlaschin spent so much time evangelizing the special abilities of F#, it was at times hard to translate the techniques he demonstrated into other, less-functionally-oriented languages (like Javascript/Typescript, for example).

Overall, this was a solid book that I would recommend for folks who are interested in going deeper in the functional programming paradigm. And the Domain-Driven Development model was useful for understanding the thinking behind the Redux state management framework that is very popular for front-end applications.

Still, the book has some weaknesses of spotty depth and sort of peters out towards the end.
2 reviews
October 16, 2021
Two for the price of one

A well written and well thought out book where you can learn two things at once without feeling overwhelmed or either feeling watered down, although it leans a bit more towards FP than DDD. You won't become an expert in either but you'll definitely have a good theoretical grounding at the end.

The book uses a fictitious case study that, while being necessarily simple, is still complex and believable enough to serve its purpose. It also doesn't oversell DDD as a silver bullet/panacea which I appreciated - the rough edges and tradeoffs of the approach (especially when using an explicit FP language) are openly noted.

The only negative I have is that while most fundamental F# concepts and syntax are explained quite thoroughly in the first two thirds of the book, in the last third they're suddenly glossed over as if you've magically gone off and learned a whole bunch of things on your own. This is jarring and a bit annoying but overall a minor issue.

Highly recommended.
Profile Image for Fábio Fortkamp.
106 reviews3 followers
November 30, 2023
This book opened a new world of possibilities in the software development world. The author clearly knows what he writes about and explains it very clearly. I like the ordering: a general theoretical review but with a practical problem in mind, then focus on types, than focus on functions and actual execution. This resembles how a real-life project would be developed (in iterations, of course).

What I actually don't like are the implementation details. The author should make it more clear that a proper knowledge of the F# programming language is required, and should make the examples more self-contained. The code examples are larger than simple snippets that show some concepts, but are not complete and cannot be executed. There are also no examples of real input data. I began to type along the examples, but got frustrated when I saw that I could never test the code.

Nevertheless, this book taught me important concepts, like "function as a type" and validated my view that "every little concept should have its own named class/type/function".
Profile Image for Damian Zydek.
43 reviews3 followers
October 31, 2020
This book teaches by an example. The author took an examplary project done with a functional programming approach and described three phrases from it (Analysis, Design, Implementation).

Part I - Analysis - Discovering Domain (general knowledge).
For me, it is the best chapter of all.
The author starts with the event storming session for discovering events, commands, and subdomains in problem space. After this, he creates a solution space with bounded contexts and relationships within them (context map).

Part II - Design - Designing the Domain Model (with F# types).
It is a great introduction to functional thinking - the reason why I read this book.

Part III - Implementation - Implementing the Domain Model (with F#)
It describes the most common implementation decisions in F# approaches (object persistence, error handling, managing dependencies, testing, etc.). If you are not planning to use functional programming, you can skim this part.
January 26, 2021
It's a good reading for people interested on learning about Domain Driven Design using real world business applications.
Really well written book, its first two parts are extremely beginner friendly, but the last (and most important part) not as much. The last section of the book assumes you're already familiar with some of F# syntax and constructors, although, one can easily follow up the book until it's end without knowing it.
Sometimes I felt like it missed showing up the entire view of the project and keeping the reader updated about it, and the Functional Error Handling and Pipeline with functions chapters could benefit from more space in the book, as some others previous chapters have.
It's an amazing software development book, and a good guide for people who wants insights on how to create and maintaining a real world application using F#.
Profile Image for Kevin Roche.
23 reviews
August 9, 2021
Good high level guide to DDD using the functional programming paradigm

The functional programming paradigm is an excellent match for Domain driven development and this book provides a helpful walkthrough of some of the specific techniques that can be applied to the practice.
The opening chapters give a high level grounding in DDD concepts (Event storming, Bounded contexts, Ubiquitous language, etc.) and the following chapters take a deeper dive into implementing them using a functional approach.
F# is the author's language of choice and we get to see how flexible it can be in modelling business domain requirements.
Neither a thorough guide to DDD nor F# this book nevertheless plays an essential role in demonstrating the utility of the functional programming paradigm to DDD.
14 reviews
August 10, 2020
This book walks you through the key concepts of Domain Driven Design in a practical and easy to grok manner. Examples are well crafted and do not require expertise of F# (I read it with a little knowledge of a similar language, Kotlin). It helped me learn the "why" behind functional patterns.

The journey starts with identifying the Vocabulary for a Domain (ubiquitous language) using Event Storming. Next modeling with Types is covered. Workflows are represented with Functions along with the Types. Second part covers implementation strategies - dependency injection, handling effects with railway oriented programming and so on.
Profile Image for Ferran Velasco Olivera.
14 reviews1 follower
November 26, 2021
Really good book to get a clear view of what it is to start a project from scratch making use of Domain-Driven Design and functional programming. Even if you don't know anything about how F# works, the author of the book makes really easy to follow how all the design and development of a project in DDD with functional programming should be done in F#. Nevertheless, the programming language used in the book is not a constraint for the book being enjoyed and learned from. I would recommend this book to anyone who wants to start a new project using DDD or functional programming no matter what the language preferred to use.
21 reviews2 followers
August 25, 2020
Really fantastic book. It has made me completely change some fundamental ways I design software.

The book uses F# in the design implementations, a language that I have never used, though I have some years of functional programming experience. It isn't an intro to F# but either because of its simplicity or the author's incredible teaching ability, everything makes sense. You don't need any background in the language.

I really can't say enough good things about this book. Highly recommended.
Displaying 1 - 30 of 78 reviews

Can't find what you're looking for?

Get help and learn more about the design.