NET-Microservices-Architecture-For-Containerized-NET-Applications
Total Page:16
File Type:pdf, Size:1020Kb
i EDITION v2.2.1 DOWNLOAD available at: https://aka.ms/microservicesebook PUBLISHED BY Microsoft Developer Division, .NET and Visual Studio product teams A division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2019 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. This book is provided “as-is” and expresses the author’s views and opinions. The views, opinions and information expressed in this book, including URL and other Internet website references, may change without notice. Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred. Microsoft and the trademarks listed at http://www.microsoft.com on the “Trademarks” webpage are trademarks of the Microsoft group of companies. Mac and macOS are trademarks of Apple Inc. The Docker whale logo is a registered trademark of Docker, Inc. Used by permission. All other marks and logos are property of their respective owners. Co-Authors: Editors: Cesar de la Torre, Sr. PM, .NET product team, Microsoft Corp. Mike Pope Bill Wagner, Sr. Content Developer, C+E, Microsoft Corp. Steve Hoag Mike Rousos, Principal Software Engineer, DevDiv CAT team, Microsoft Participants and reviewers: Jeffrey Richter, Partner Software Eng, Azure team, Microsoft Steve “ardalis” Smith - Software Architect and Trainer - Ardalis.com Jimmy Bogard, Chief Architect at Headspring Ian Cooper, Coding Architect at Brighter Udi Dahan, Founder & CEO, Particular Software Unai Zorrilla, Architect and Dev Lead at Plain Concepts Jimmy Nilsson, Co-founder and CEO of Factor10 Eduard Tomas, Dev Lead at Plain Concepts Glenn Condron, Sr. Program Manager, ASP.NET team Ramon Tomas, Developer at Plain Concepts Mark Fussell, Principal PM Lead, Azure Service Fabric team, Microsoft David Sanz, Developer at Plain Concepts Diego Vega, PM Lead, Entity Framework team, Microsoft Javier Valero, Chief Operating Officer at Grupo Solutio Barry Dorrans, Sr. Security Program Manager Pierre Millet, Sr. Consultant, Microsoft Rowan Miller, Sr. Program Manager, Microsoft Michael Friis, Product Manager, Docker Inc Ankit Asthana, Principal PM Manager, .NET team, Microsoft Charles Lowell, Software Engineer, VS CAT team, Microsoft Scott Hunter, Partner Director PM, .NET team, Microsoft Miguel Veloso, Sr. Consultant at Turing Challenge Dylan Reisenberger, Architect and Dev Lead at Polly Nish Anil, Sr. Program Manager, .NET team, Microsoft ii Contents Introduction ................................................................................................................................................. 1 About this guide .................................................................................................................................................................. 1 Version..................................................................................................................................................................................... 1 What this guide does not cover .................................................................................................................................... 2 Who should use this guide ............................................................................................................................................. 2 Related microservice and container-based reference application: eShopOnContainers ....................... 2 Send us your feedback! .................................................................................................................................................... 3 Introduction to Containers and Docker .................................................................................................. 4 What is Docker? ....................................................................................................................................................................... 5 Comparing Docker containers with virtual machines ........................................................................................... 6 A simple analogy ................................................................................................................................................................. 7 Docker terminology ................................................................................................................................................................ 8 Docker containers, images, and registries .................................................................................................................. 10 Choosing Between .NET Core and .NET Framework for Docker Containers ................................... 12 General guidance .................................................................................................................................................................. 12 When to choose .NET Core for Docker containers .................................................................................................. 13 Developing and deploying cross platform ............................................................................................................ 13 Using containers for new (“green-field”) projects ............................................................................................... 14 Creating and deploying microservices on containers ....................................................................................... 14 Deploying high density in scalable systems .......................................................................................................... 14 When to choose .NET Framework for Docker containers ..................................................................................... 15 Migrating existing applications directly to a Windows Server container .................................................. 15 Using third-party .NET libraries or NuGet packages not available for .NET Core .................................. 15 Using .NET technologies not available for .NET Core ........................................................................................ 15 Using a platform or API that does not support .NET Core .............................................................................. 16 Decision table: .NET frameworks to use for Docker ................................................................................................ 16 What OS to target with .NET containers ..................................................................................................................... 17 Official .NET Docker images ............................................................................................................................................. 19 .NET Core and Docker image optimizations for development versus production ................................ 19 Architecting container and microservice-based applications ........................................................... 21 Container design principles ......................................................................................................................................... 21 Containerizing monolithic applications ....................................................................................................................... 22 Deploying a monolithic application as a container ............................................................................................ 24 Publishing a single-container-based application to Azure App Service .................................................... 24 iii State and data in Docker applications ......................................................................................................................... 25 Service-oriented architecture........................................................................................................................................... 28 Microservices architecture ................................................................................................................................................ 28 Additional resources ....................................................................................................................................................... 30 Data sovereignty per microservice ................................................................................................................................ 30 The relationship between microservices and the Bounded Context pattern ........................................... 32 Logical architecture versus physical architecture ..................................................................................................... 33 Challenges and solutions for distributed data management ............................................................................. 34 Challenge #1: How to define the boundaries of each microservice ............................................................ 34 Challenge #2: How to create queries that retrieve data from several microservices ............................ 34 Challenge #3: How to achieve consistency across multiple microservices ............................................... 36 Challenge #4: How to design communication across microservice boundaries .................................... 37 Additional resources ......................................................................................................................................................