Domain-Driven Design with Golang

Book description

Understand the concept of Domain-driven design and build two DDD systems from scratch that can be showcased as part of your portfolio

Key Features

  • Explore Domain-driven design as a timeless concept and learn how to apply it with Go
  • Build a domain-driven monolithic application and a microservice from scratch
  • Leverage patterns to make systems scalable, resilient, and maintainable

Book Description

Domain-driven design (DDD) is one of the most sought-after skills in the industry. This book provides you with step-by-step explanations of essential concepts and practical examples that will see you introducing DDD in your Go projects in no time. Domain-Driven Design with Golang starts by helping you gain a basic understanding of DDD, and then covers all the important patterns, such as bounded context, ubiquitous language, and aggregates. The latter half of the book deals with the real-world implementation of DDD patterns and teaches you how to build two systems while applying DDD principles, which will be a valuable addition to your portfolio. Finally, you’ll find out how to build a microservice, along with learning how DDD-based microservices can be part of a greater distributed system. Although the focus of this book is Golang, by the end of this book you’ll be able to confidently use DDD patterns outside of Go and apply them to other languages and even distributed systems.

What you will learn

  • Get to grips with domains and the evolution of Domain-driven design
  • Work with stakeholders to manage complex business needs
  • Gain a clear understanding of bounded context, services, and value objects
  • Get up and running with aggregates, factories, repositories, and services
  • Find out how to apply DDD to monolithic applications and microservices
  • Discover how to implement DDD patterns on distributed systems
  • Understand how Test-driven development and Behavior-driven development can work with DDD

Who this book is for

This book is for intermediate-level Go developers who are looking to ensure that they not only write maintainable code, but also deliver great business value. If you have a basic understanding of Go and are interested in learning about Domain-driven design, or you’ve explored Domain-driven design before but never in the context of Go, then this book will be helpful.

Table of contents

  1. Domain-Driven Design with Golang
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
  6. Part 1: Introduction to Domain-Driven Design
  7. Chapter 1: A Brief History of Domain-Driven Design
    1. The world before DDD
      1. So, what are OOD patterns?
    2. Eric Evans and DDD
    3. Three pillars of DDD
    4. Adoption of DDD
    5. When should you use DDD?
    6. Summary
    7. Further reading
  8. Chapter 2: Understanding Domains, Ubiquitous Language, and Bounded Contexts
    1. Technical requirements
    2. Setting the scene
    3. Domains and sub-domains
    4. Ubiquitous language
      1. Benefits of ubiquitous language
    5. Bounded contexts
      1. Open Host Service
      2. Published language
      3. Anti-corruption layer
    6. Summary
    7. Further reading
  9. Chapter 3: Entities, Value Objects, and Aggregates
    1. Technical requirements
    2. Working with entities
      1. Generating good identifiers
      2. A warning when defining entities
      3. A note on object-relational mapping
    3. Working with value objects
      1. How should I decide whether to use an entity or value object?
    4. The aggregate pattern
      1. Discovering aggregates
      2. Designing aggregates
      3. Aggregates beyond a single bounded context
    5. Summary
    6. Further reading
  10. Chapter 4: Exploring Factories, Repositories, and Services
    1. Technical requirements
    2. Introducing the factory pattern
      1. Entity factories
    3. Implementing the repository pattern in Golang
    4. Understanding services
      1. Domain services
      2. Application services
    5. Summary
  11. Part 2: Real -World Domain-Driven Design with Golang
  12. Chapter 5: Applying Domain-Driven Design to a Monolithic Application
    1. Technical requirements
    2. What do we mean when we say monolithic application?
    3. Setting the scene
    4. Getting started with our CoffeeCo system
      1. Implementing our product repository
      2. Adding an infrastructure service for payment handling
      3. Paying with CoffeeBux
      4. Adding store-specific discounts
      5. Extending our service
    5. Summary
    6. Further reading
  13. Chapter 6: Building a Microservice Using DDD
    1. Technical requirements
    2. What do we mean by microservices?
      1. What are the benefits of microservices?
      2. What are the downsides of microservices?
    3. Should my company adopt microservices?
    4. Setting the scene (again)
    5. Building a recommendation system
    6. Revisiting the anti-corruption layer
    7. Exposing our service via an open host service
    8. Summary
  14. Chapter 7: DDD for Distributed Systems
    1. Technical requirements
    2. What is a distributed system?
      1. CAP theorem and databases
    3. Distributed system patterns
      1. CQRS
      2. EDA
    4. Dealing with failure
      1. Two-phase commit (2PC)
      2. The saga pattern
    5. What is a message bus?
      1. Kafka
      2. RabbitMQ
      3. NATS
    6. Summary
    7. Further reading
  15. Chapter 8: TDD, BDD, and DDD
    1. Technical requirements
    2. TDD
      1. Adding a test
      2. Run the test we just wrote – it should fail (and we should expect it to)
      3. Write as little code as possible to pass the test
      4. Refactoring
    3. BDD
    4. Summary
  16. Index
    1. Why subscribe?
  17. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Domain-Driven Design with Golang
  • Author(s): Matthew Boyle
  • Release date: December 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781804613450