Domain-Driven Design with Golang - Matthew Boyle - E-Book

Domain-Driven Design with Golang E-Book

Matthew Boyle

0,0
32,39 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 182

Veröffentlichungsjahr: 2022

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Domain-Driven Design with Golang

Use Golang to create simple, maintainable systems to solve complex business problems

Matthew Boyle

BIRMINGHAM—MUMBAI

Domain-Driven Design with Golang

Copyright © 2022 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Gebin George

Publishing Product Manager: Pooja Yadav

Senior Editor: Kinnari Chohan

Technical Editor: Pradeep Sahu

Copy Editor: Safis Editing

Project Coordinator: Deeksha Thakkar

Proofreader: Safis Editing

Indexer: Subalakshmi Govindhan

Production Designer: Aparna Bhagat

Developer Relations Marketing Executive: Sonakshi Bubbar

Technical Reviewers: Andrea Medda, Matthew Williams, Chris Shepherd

First published: December 2022

Production reference: 2141222

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80461-345-0

www.packt.com

To my partner Hannah, who is always supportive of my schemes, no matter how ludicrous (writing this book being one of my wilder ones).

To the memory of my mother Sarah, whom I miss every day and I’m certain would have displayed this book proudly (but never have read it).

Contributors

About the author

Matthew Boyle is an experienced technical leader in the field of distributed systems, specializing in using Go. He has worked at huge companies such as Cloudflare and General Electric, as well as exciting high-growth startups such as Curve and Crowdcube. Matt has been writing Go for production since 2018 and often shares blog posts and fun trivia about Go over on Twitter (@MattJamesBoyle).

Andrea Medda is an experienced Go engineer from Sardinia. Andrea has a strong interest in clean, maintainable code that scales.

About the reviewers

Matthew Williams is a (mainly) backend Software Engineer generally working in Java or Kotlin, who has dabbled in Go. Regardless of the language used, he is a proponent of Domain-Driven Design, Test-Driven Development and occasionally, Frustration-Driven Development. Originally a University of Birmingham Computer Science classmate of the author, he has spent time working across both the public and private sectors in the UK and Australia. Working for the likes of the Science and Technology Facilities Council, SAP, and Tyro on domains including scientific research proposals, e-commerce, and payments, the need to understand and use the language of the domain has always been clear.

Chris Shepherd is currently employed as a Systems Engineer building large scale, highly-available and robust distributed systems. He has worked within software engineering for more than seven years, the majority of which have been dedicated to writing Go. He has worked for both big-name companies, such as IBM and Cloudflare, and fast paced, hyper-growth startups, spanning across many different industries, including finance, cybersecurity, and the public sector. He received a BSc in Computer Science from De Montfort University and is currently employed by Cloudflare, where he designs, develops, and maintains highly scalable event-driven microservices in Go.

Table of Contents

Preface

Part 1: Introduction to Domain-Driven Design

1

A Brief History of Domain-Driven Design

The world before DDD

So, what are OOD patterns?

Eric Evans and DDD

Three pillars of DDD

Adoption of DDD

When should you use DDD?

Summary

Further reading

2

Understanding Domains, Ubiquitous Language, and Bounded Contexts

Technical requirements

Setting the scene

Domains and sub-domains

Ubiquitous language

Benefits of ubiquitous language

Bounded contexts

Open Host Service

Published language

Anti-corruption layer

Summary

Further reading

3

Entities, Value Objects, and Aggregates

Technical requirements

Working with entities

Generating good identifiers

A warning when defining entities

A note on object-relational mapping

Working with value objects

How should I decide whether to use an entity or value object?

The aggregate pattern

Discovering aggregates

Designing aggregates

Aggregates beyond a single bounded context

Summary

Further reading

4

Exploring Factories, Repositories, and Services

Technical requirements

Introducing the factory pattern

Entity factories

Implementing the repository pattern in Golang

Understanding services

Domain services

Application services

Summary

Part 2: Real -World Domain-Driven Design with Golang

5

Applying Domain-Driven Design to a Monolithic Application

Technical requirements

What do we mean when we say monolithic application?

Setting the scene

Getting started with our CoffeeCo system

Implementing our product repository

Adding an infrastructure service for payment handling

Paying with CoffeeBux

Adding store-specific discounts

Extending our service

Summary

Further reading

6

Building a Microservice Using DDD

Technical requirements

What do we mean by microservices?

What are the benefits of microservices?

What are the downsides of microservices?

Should my company adopt microservices?

Setting the scene (again)

Building a recommendation system

Revisiting the anti-corruption layer

Exposing our service via an open host service

Summary

7

DDD for Distributed Systems

Technical requirements

What is a distributed system?

CAP theorem and databases

Distributed system patterns

CQRS

EDA

Dealing with failure

Two-phase commit (2PC)

The saga pattern

What is a message bus?

Kafka

RabbitMQ

NATS

Summary

Further reading

8

TDD, BDD, and DDD

Technical requirements

TDD

Adding a test

Run the test we just wrote – it should fail (and we should expect it to)

Write as little code as possible to pass the test

Refactoring

BDD

Summary

Index

Other Books You May Enjoy

Preface

Welcome to this book on Domain-driven design with Golang!

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 contexts, Ubiquitous Language, aggregates, and more. The latter half of this book deals with the real-world implementation of Domain-driven design patterns, and teaches you to build two systems whilst 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.

Who this book is for

This book is intended for intermediate Go developers who are looking to take their enterprise skills to the next level, however, I really hope I have made it accessible enough that beginners can follow along too.

If you have never written Go before, but have some familiarity with DDD, I hope this book will help you use your expertise to write Domain-driven Go in an idiomatic way.

Finally, if you are an expert in DDD and in Golang, I hope this book serves as a great reference that you can pick up from time to time when you can’t quite remember something.

What this book covers

Chapter 1, A Brief History of Domain-Driven Design helps you learn about the origins of DDD – no Golang in this chapter!

Chapter 2, Understanding Domains, Ubiquitous Language, and Bounded Contexts teaches you these core domain-driven topics.

Chapter 3, Entities, Value Objects, and Aggregates will help you learn a few more DDD topics.

Chapter 4, Exploring Factories, Repositories, and Services is the final chapter of Part 1, and sees us learn three more DDD patterns that will help cement our understanding.

Chapter 5, Applying DDD to a Monolithic Application teaches how we can apply domain-driven design to both an existing monolithic application, but also to a new one we will build together.

Chapter 6, Building a Microservice using DDD shows how to build a microservice using DDD that is resilient to failure.

Chapter 7, DDD for Distributed Systems takes you through how DDD can be applied to entire distributed systems as well as covering topics such as message queues at a foundational level.

Chapter 8, TDD, BDD and BDD is a bonus chapter that covers how test-driven development, behaviour-driven development, and domain-driven development can be complimentary patterns.

To get the most out of this book

Software/hardware covered in the book

Operating system requirements

Go 1.19.3 or above

Windows, macOS, or Linux

VS Code or Goland

Docker

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Domain-Driven-Design-with-GoLang. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/lXo4T.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “Firstly, we will define a Point in the following code block.”

A block of code is set as follows:

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Domain-Driven Design With Golang, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

Scan the QR code or visit the link below

https://packt.link/free-ebook/9781804613450

Submit your proof of purchaseThat’s it! We’ll send your free PDF and other benefits to your email directly

Part 1: Introduction to Domain-Driven Design

Part 1 of Domain-driven design with Golang focuses on ensuring you are familiar with the core DDD concepts. We start by exploring the history of DDD, as I truly believe that context is important when applying software patterns. We then move on to exploring each DDD concept in isolation by firstly learning the theory behind them and then applying them with Golang code. This lays a great foundation for Part 2, where we will build two projects from scratch and use all the DDD concepts we learnt in this first part.

This part comprises the following chapters:

Chapter 1, A Brief History of DDDChapter 2, Understanding Domains, Ubiquitous Language, and Bounded ContextsChapter 3, Entities, Value Objects, and AggregatesChapter 4, Factories, Repositories, and Services