As Python continues to grow in popularity, projects are becoming larger and more complex. Many Python developers are now taking an interest in high-level software architecture patterns such as hexagonal/clean architecture, event-driven architecture, and strategic patterns prescribed by domain-driven design (DDD). But translating those patterns into Python isn't always straightforward.
With this practical guide, Harry Percival and Bob Gregory from MADE.com introduce proven architectural design patterns to help Python developers manage application complexity. Each pattern is illustrated with concrete examples in idiomatic Python that explain how to avoid some of the unnecessary verbosity of Java and C# syntax. You'll learn how to implement each of these patterns in a Pythonic way.
Architectural design patterns include:
Dependency inversion, and its links to ports and adapters (hexagonal/clean architecture) Domain-driven design's distinction between entities, value objects, and aggregates Repository and Unit of Work patterns for persistent storage Events, commands, and the message bus Command Query Responsibility Segregation (CQRS) Event-driven architecture and reactive microservices
I've picked this one because of pure curiosity. The majority of my experience is with strongly & statically typed programming languages - applying DDD in such conditions appears very different than in Python (which is relatively new to me). So I wanted to check this out - whether certain particles (e.g. dependency injection, abstracting the services out, etc.) make any sense here or maybe there are some very different patterns to be used.
Before I state my opinion whether the book is good or not - one more comment. About the title: I find it very misleading (however, fortunately, I've made some background check first, so I knew what to expect). This is not really a book about architecture patterns (like EAI) in general - it's far more about so-called "canonical" application of DDD & related patterns (e.g. CQRS). It's a popular subset, very opinionated & sometimes very far from pragmatism & "feet on the ground" attitude, but still good to get familiar with.
So, in the end, despite of the flaws (e.g. I disagree with "canonical" approach to DDD which is - according to myself - exactly opposite to what's the most important in DDD) I've enjoyed the read. The book is very well written, all the descriptions, rationale & clarifications are clear, easy to grasp & have a proper takt, so the reader doesn't get either bored or overwhelmed. Personally I've got all the answers I've expected but that DOESN'T MEAN I'd use the "patterns" proposed by this book 1:1 in my solutions. Good stuff to get through & make your own mind of what's useful and what's not.
به این مسئله توجه کنید. یک سیستم فروشگاهی را در نظر بگیرید که میلیونها کاربر فعال دارد. از محصولی تنها یک عدد باقی مانده است. ممکن است چند کاربر به صورت همزمان در حال مشاهده صفحه آن محصول باشند. اگر یکی از مشتریان محصول را خرید، دیگران که در حال مشاهده صفحه بودند چه زمانی باید متوجه این قضیه شوند؟ به چه شکل این سیستم بزرگ را از لحاظ کارایی باید مدیریت کنیم (سیستم کند نشود؟
این کتاب در سطح پیشرفته قرار دارد و مفاهیم جدید طراحی و معماری نرمافزار را مانند معماری تمیز، طراحی قلمرو محور، مایکروسرویسها و معماری رویداد محور با استفاده از زبان برنامهنویسی پایتون آموزش میدهد. به نظرم در دو حالت کتاب را مطالعه کنید: ۱. پایتون را در سطح پیشرفته بلد هستید و میخواهید سطح دانش خود را در حوزههای دیگر مانند معماری و طراحی بهبود ببخشید. ۲. بر روی سیستمی کار میکنید که تعداد کاربران فعال آن میلیونی (یا بیشتر) است.
This is an amazing book. One of the best books I've read on the topic for the following reasons: - Very easy to follow - Each presented concept end up with a pros and cons table - Exceptional sense of humor that makes you keep reading - Straight to the point language. No filler. - Short chapter so that you can read one chapter a day - Based on a simple project - It's excellent for Pythonists that want to write robust applications
This book contains some good information, but I disliked its style very much. It takes too much effort and time to learn something from this wordy text.
If you know Java or C#, you can probably find more digestible books that cover the same topics.
For Python one trick ponies, search for the articles on Python clear architecture by Sebastian Buczyński. They are a great addition to this book. Their language is understandable and concise. Also, they contain more up-to-date information on helpful libraries.
Also, I suggest to take a look at the following books: - Python Object-Oriented Programming by Steven F. Lott and Dusty Phillips. - Robust Python by Patrick Viafore. - Clean Code in Python by Mariano Anaya.
Brilliant flow of explaining topics and answering questions arose in the reader's mind. It's well organized with the pros and cons of each concept, leaving the decision to the reader.
This felt like talking to a friend, discussing details with a sense of humour.
Reading this book after reading the theory in the DDD book and working in a python codebase with semi domain driven and event driven patterns, all the concepts finally made so much sense and made me rethink what I thought was good or bad in our codebase. I really like the pedagogical approach of this book - they show you the mud first and then when it’s clear how the mud is not ideal, they show you how to make the mud into nicely separated modules that are loosely coupled. A few things I have much better understanding of after reading this book - where to put your business logic - how to build the layer of abstraction around persistence storage for easier testing - made me like dependency injection better (especially when used with FastAPI, although the book uses Flask for the examples)
The book is indeed fun to read and the best thing that I liked about it is that even though the approach is highly opinionated, the authors remained critical and open minded about certain things, encouraging discretion and experimentation on the readers side. There are some good ideas and python tricks in this book for sure. The book made me curious about TDD and even more importantly DDD and I'm going to look into that going forward. The book would a great reference for intermediate/expert developers seeking to improve their code and practices. Most of the ideas can be easily applied beyond Python and as a matter of facts I have implemented the same solution in Typescript and Go, albeit with some variation, mostly addressing the design issues mentioned below and differences of chosen tools.
NOTE: apparently the SqlAlchemy APIs have changed since the book was published, so had to fix some deprecated calls as well.
All in all - a very good read (easily 4.75-5). Will definitely read the TDD book by Harry J.W. Percival. Also special kudos to the authors for making the book available online. I have a copy but it's nice to make it available to those who cannot have one for whatever reason.
This book explains each pattern with clear examples with pros and cons to let you decide. It also has a familiar tone as it doesn't pretend to have the last word, just a few battle tested patterns that may help you. As for myself, after finishing the book I feel convinced, but because I understand the reasons behind each pattern, not because it has a name and people in other languages use them.
I will also be reading Harry testing book to see if i like it as much as this one
This is a great introduction to domain driven design in Python. There is teething and necessary patience of course, as with any unfamiliar design philosophy that makes you scratch your head at its seemingly unnecessaryy verbose style, but Gregory and Percival have a casual and skilled didactic style that slowly onboards you, with lots of exercises to boot.
Coming from an daily workplace that espouses event-driven style but uses a Cloud provider for all the glue, I found it especially rewarding to see this all implemented locally. It really helped me understand the strength of such a design pattern.
As a potential reader I suggest: 1. You have done some basic reading or know of the existence of basic design patterns with ports and adapters 2. You are at least an intermediate level programmer
As caveats to the above: 1. My opinion is coloured because Gregory is the chief architect at my firm, and the event-driven pattern is ubiquitous throughout the company. 2. I haven't read either of the two great general domain driven design books
I was thinking about putting 4 stars at first, but eventually decided to round the rating up. Title, I think, puts a lot of things in one big pile, and might be somewhat misleading (I mean, all 3 topics are broad, and it's just one short book, so it won't cover everything in detail).
If you're looking for examples of DDD - it's a great book to read, especially part 1. Part 2 is slightly more "technical", but definitely not less interesting (maybe even more, for my liking). TDD is used "sparingly" - this is not the book about tests, it's a book about writing code that is easy to test.
1st part felt very good and natural to read right after reading Uncle Bob's "Clean Architecture" - examples of clear boundaries, ports and adapters etc. Some naming I had to get accustomed to (i literally heard "unit of work" term first time after writing soft for 10+ years), and I'm still unsure if I agree on how authors defined some boundaries, but I definitely can accept what was done.
Also want to mention 2 things that I really liked: There's a lot of code, and it's also present in Github, so you can check it out and easily follow everything authors describe, and not rely on excerpts printed in the book itself, but on your favourite IDE. And it gives a great example of building "idiomatic" "enterprisey" app from scratch in Python - as person coming from Java world, who probably still writes very Java-ey Python, I really wanted to see examples of doing things the python way - and this book provided in full.
Albeit a great book that has nice flow and goes through a lot of concepts and presents the reader with a lot of ways on how to create a truly scalable software, the new weaponry with which the book equips you in my opinion allows you to shoot yourself in the foot rather easily. Though the authors did touch on a lot of the footguns in the appendices they should have elaborated more on these in some of the chapters especially around message queues and the likes.
Really well written, non prescriptive, anticipates reader questions and sums up tradeoffs well. My biggest gripe was the central example being a warehouse system. I think they should have searched for a more ubiquitous domain and used that instead
One of the great practical books for Python I ever read. Learned simple yet powerful techniques and patterns to design production ready Python application.
Very good book for junior software engineers who don't know where to put business logic code.
The design proposed in the book could be some how complicated and overkill but the process to that design can make you better software engineer. This book does not make a dogmatic approach to problems it tries to solve, it also gave the why, the pros and cons.
This book gave me so much new information to think about that I'm going to have to let it settle for a while then come back and read it all again.
I'm pretty sure that the mere fact that I have read this is going to save me a lot of trouble in the not too distant future, and stop me going down paths that would not be a good idea in the long run (though, somewhat gratifyingly, it also confirmed my ideas about a few things as well, though even then it gave me something extra to think about).
Very well written thorough, with easy to read examples demonstrating exactly what the authors mean at every stage. Highly recommended for anybody looking to build anything larger than a small CRUD app.
When I started reading this book, I made a mistake by not believing the authors. In the introduction, they make you understand that it is not a typical Python tutorial material. However, when I first encountered it on their website, I was going to look through, as usual, skipping familiar aspects and paying attention to anything interesting. But, this attitude is wrong in this case. You MUST examine the code, and immediately stop, if anything is not completely clear. Because, down the road, reading would become a waste of your time. At first, you would be surprised with some novel idea, later you would think well okay deal with it later. Soon enough, you would lose the track completely. That was my experience at the first read. It is not a fast read, but very useful upon proper attention. Would definitely read it the third time.
The best book to get familiar with DDD if you are Python developer. A little bit of theory just enough to understand basic concepts and plenty of code examples showing how various principles apply in day to day work with code. I also really like that authors are not dogmatic about whole DDD and clearly show that each element brings value but also trade-offs to consider by the team.
Start here, leave blue and red books on a shelf for later once you have some experience with DDD and are ready to master details of it.
I enjoyed this one enough I'll probably read it twice. Fun and well written, basically never a slog. There's not a lot written on practical large scale application design in python and this was a real treat. I see a ton of ideas I'll apply immediately and others I've already been doing intuitively. Highly recommended.
I'm at Chapter 3 now and I would say this is one of the best technical books I've ever read. Lots of exercises, less filler, useful appendixes & github repo. Love it.
I've learnt a lot from the book. There is a good balance of practice and theory in the book. There are a lot of useful links and references for expanding your knowledge on the topic too.
Really book full of practical examples. It is not very chatty and still gives you enough curiosity to check the presented patterns deeper. Concise and readable code in Python is a great choice for a book explaining the architecture patterns. Even available online at https://www.cosmicpython.com/.
This is an unexpectedly great introduction to domain-driven design (DDD) in Python: * it's exactly the right size; it's not an overly-large kitchen sink book, but just enough to express the overall idea of how to go about developing an entire event-driven DDD architecture * there is a surprising amount of code, but it is always clear, well-annotated, and in appropriate portions; it's unapologetic about being a readable programming book * the assembly of the architecture is done in the flow of developing the application; we see the different components not in arbitrary isolation, but in the context of test-driven development, which is followed all the way through * the use of different levels of testing in the development of the application is well articulated; we see unit tests, edge-to-edge tests, and the end-to-end tests in proportion, and how to effectively shift between them throughout development * the entire concept of edge-to-edge, and how well it aligns with DDD services and aggregates, was really pleasant to observe * the sizes of chapters are not only appropriately concise, but are carefully scoped to introducing the architectural concept being developed * the tone was jovial and the language was clear; it was pleasurable reading * when the authors disagreed with each other, they were clear to articulate what and why; in general, they tried to avoid any unqualified recommendations, seeking out pros and cons for every direction
Overall, I came away very pleased; this book isn't groundbreaking but that's a sign of maturity in DDD. You can disagree with their choices, but it's hard to disagree with the quality of their approach. This is a great example of what programming books can be now that the Internet can serve the roles of references and manifestos.
I was a little worried after reading the introduction :D
Who is this book for according to the authors? For Software Engineers that are acquainted with Python but have some knowledge gaps regarding DDD, EDA and Enterprise Architecture.
Who am I? A Software Engineer that has absolutely zero experience with Python and quite a lot of knowledge about DDD, EDA and Enterprise Architecture.
Anyway, fortunately I've won against these adversities and enjoyed the book eventually.
I would describe it as a short introduction (pocket reference was a term used long time ago!) into most of the popular design-related topics in software these days. DDD, EDA, CQRS, DI, UoW etc. The book is small and learning starts literally from the beginning so you can't expect too much details. However, I have to admit that the authors were able to succeed in the most important aspect of software books - finding the right balance between delivering content and not overwhelming the recipient. The example use case was nice and easy to understand (with a lot of tests describing it). Design choices were rational and explained well.
The biggest problem with "Architecture Patterns with Python" I have is quite fundamental in nature. Why the hell are you trying to treat Python as regular strongly typed and static language? Wouldn't following all the advices from the book eventually lead to the question: "Wait a minute... There are languages that allow doing most of the hard things here out of the box... Let's use Java or C#!". I'm just not sure if being so strict doesn't diminish all the beauty, practicality and minimalism of Python!
I would vote for three stars but I don't want to be ignorant :) My lack of knowledge of Python gives an extra star as a safety net!
Must read if you are programming python web apps and have interest in DDD. Even just for exploring DDD it is a nice start, Evan's DDD is harder to follow then this great guide. Reading Evans DDD along this one I think is a great idea.
The book uses a nice example from furniture industry logistics. Way easier to follow than Evan's DDD examples. The example is well built into chapters that build upon one another. Every concept is introduced after the need for it had arised. E.g. you start the project with just two files model.py, test_model.py and you add repository.py in next chapter. You extract a whole module by the end of the book but you go through the whole process of reaching an application with MessageBus, CQRS, repositories etc.
Things I loved about the book
- It uses modern python - types, dataclass, protocols, etc. - It uses a TDD approach to build the examples - It uses an opinionated approach to using only doubles instead of mocks (matter of personal taste but really well done in the book) - Whenever a pattern is introduced a table with pros and cons is shown - Great resources for follow up readings - Shows a nice modern docker compose based structure for a project
Things I would love to see in a future edition
- A chapter about FastAPI - A chapter about asyncio
You shouldn't try to implement everything in the book. You can be onboard with some ideas, or find others inapplicable for your use cases. Nevertheless they are explained well and easy to understand.
The purpose of the book is to translate famous architecture pattern into Python, such as DDD, TDD and Event Driven Design . I believe this book is for an engineer who already know what DDD means. I had to chat with GPT to understand what DDD means, since i didn’t have prior experience with it.
The authors describe patterns like Domain model, Repository, Layers, Adapters, Unit of Work, and the Event Driven Design. The code snippets in the book is in Flask, but it doesn’t require to have an experience in Flask since its simple and straightforward.
I really liked the explanation flow, at the end of each chapter the authors raise a problem that gets solved in the next chapter. I liked that the authors reflect real word examples in the book. The tone of writing is simple, informal, friendly. I liked the reference they shared in the book whether talks, articles, or event other books.
They provided a Github repo that contains all examples from the book, with each chapter having its own branch
These were especially insightful for me [value objects, domain object, ports and adapters, and the idea of DIP]
There are some parts I didn’t fully understand, maybe I’ll come back to reread them, especially the chapters on Driven Design.
I really enjoyed reading his book and I recommend it to anyone working with Python. It open your eyes to many concepts.
"Architecture Patterns with Python" is an insightful and invaluable resource for both novice and experienced developers looking to enhance their understanding of software architecture and design patterns in Python. The book is well-structured, offering clear and concise explanations that make complex concepts accessible. Each pattern is not only thoroughly explained but is also accompanied by practical examples and real-world scenarios, which greatly aids in comprehension and application. The authors, Harry Percival and Bob Gregory, have done an excellent job of breaking down the patterns into digestible sections, making it easy to follow along and apply the lessons to one's own projects.
One of the book's strengths is its focus on test-driven development, which ensures that readers understand the importance of writing tests for reliable and maintainable code. This approach not only improves the quality of the code but also enhances the reader's coding skills. Additionally, the book covers a wide range of patterns and best practices, which are applicable to various types of projects, making it a versatile resource for many.
The writing style is engaging and encouraging, which makes the learning process enjoyable and motivating. The authors’ expertise and experience are evident, providing depth and credibility to the content.
The best part of this book is, it doesn't try to present the core idea of DDD in a too generic way. Instead, the authors pick up a domain that they're very familiar with and work their way through different concepts. To me, DDD still feels way too Javaesque, and a lot of the functionalities are already well implemented and tested in frameworks like Django.
Also, the book desperately proselytizes TDD—making the process of following along and working through the examples quite difficult. Sure, TDD enjoys its fair share of benefits, but its Tenet-likeeffect- before-cause workflow forces you read the book asynchronously; disrupting the channel of concentration intermittently.
I found the second part of the book way more interesting and it resonated better with my pre-conceived bias. Here, I picked up quite a few new concepts that I intend to experiment with in the future. Overall, I'm glad that I picked up the book!