<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anders Gill on Medium]]></title>
        <description><![CDATA[Stories by Anders Gill on Medium]]></description>
        <link>https://medium.com/@anders.gill?source=rss-cc4039c78bae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*puf7ma_n5asNMZ7-UeBZqA.jpeg</url>
            <title>Stories by Anders Gill on Medium</title>
            <link>https://medium.com/@anders.gill?source=rss-cc4039c78bae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:42:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anders.gill/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Part 1: Domain Driven Design like a pro ]]></title>
            <link>https://medium.com/raa-labs/part-1-domain-driven-design-like-a-pro-f9e78d081f10?source=rss-cc4039c78bae------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9e78d081f10</guid>
            <category><![CDATA[ddd]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Anders Gill]]></dc:creator>
            <pubDate>Sat, 09 Nov 2019 14:17:50 GMT</pubDate>
            <atom:updated>2019-11-09T14:17:50.887Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Introduction phase: Tackling the ambiguity of DDD</strong></h4><p>Domain modeling is hard. Teaching &amp; learning about domain modeling is even harder. So, my aim is to help you on your journey on learning this vast topic, giving you a solid fundamental understanding of what it means to go Domain Driven. Conceptual notions and digging into examples is what this series is all about. People often dive straight into developing Line of Business applications (LoB) with code, but not knowing what DDD really stands for before implementation can lead to disaster. Historically, monolithic architectures have been the king, and microservices has slowly made its adoption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qRXapFKimateOCZbltSnxg.jpeg" /><figcaption>Picture of me before I started learning DDD</figcaption></figure><p>There are tons of frameworks out on the internet which are more aligned towards using the DDD approach in implementation, but encapsulating a whole lot of principles just because it sounds «appropriate» is not good enough. There must be a clear reasoning behind decisions, and we will look at specific areas and benefits of implementing DDD where it makes sense to do so. By the end of this series, you will not only see that DDD is more than a collection of patterns, but hopefully also understand the philosophy behind it. Before we crack it open, there are some prerequisites that needs to be in order. Demystifying these complex prerequisites is essential before you will be a pro on developing with the DDD mindset.</p><p>This series attempts to take away the super-complicated vocabulary and abstract these parts into simple and easily digestible drawings and small pieces of information. Hopefully, all the buzzwords will make much more sense to you and you feel ready to dive into the world of DDD. Secondly, this series will work as a starting point for people who are new to the concepts of Software Engineering, and it is recommended to follow it from top to bottom before choosing a learning path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0vRUDWoNphgqgvVs-CewWQ.jpeg" /><figcaption>Game plan of how to become a pro in DDD</figcaption></figure><p>This series will consist of multiple parts. The introductory section is split into two parts (you are now reading part 1). There will be at least one part for each track (uncertain of the number at the time of writing). This is as earlier mentioned recommended to be completed before diving head first into your specific area of choice. You can choose to learn more about the Business track or the Developer track later on. By staying cooperative to the process, you should by the end of the series have enough knowledge to continue your DDD journey with practical approaches and implementations. Each respective track has its own focus points, maybe you’ll even finish them all? Awesome, now let’s get going!</p><p><em>Disclaimer: Being a data scientist myself for the last 4–5 years, and coming from a background as a software engineer, I have personally not stayed updated on the latest trends within concepts and design principles within software integration. I am therefore always open for corrections, fixes, suggestions and other helpful ideas that might arise from reading this series. The series has resulted from countless hours of reading, talking to educated people, watching tutorials and YouTube videos.</em></p><p>Let‘s start off by listing the jargon I will abstract from the introductory paragraph.</p><p>• Microservices</p><p>• Monolithic architecture</p><p>• LOB (Line of Business) applications</p><p>I am sure that once we get going on explaining these concepts, new question marks will arise, and we will continue to point them out and explain these.</p><h4><strong>Microservices</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBDRBJkDOGYQ6r2Tx5-wvQ.png" /><figcaption>Microservices architecture</figcaption></figure><p>A Microservices architecture seeks to package its components (services) into completely independent units. That’s the easiest way to put it. Everything should be decoupled so that each microservice can scale independently. Previously, software projects were often big monolithic monsters that were highly coupled together and hard to maintain. You usually chose a programming language and process and just stuck with it. With Microservices however, you are free to pick the best tools for each particular job. When starting on a project, you might start with a few larger services and carve them up into Microservices as the logical boundaries reveal themselves. However, if you are struggling with articulating with reasoning for splitting a larger service into microservices, then maybe the best way forward is to keep the larger service as it is. By working in a modular way, like Microservices allows you to, you have a better chance of rapidly fixing problems and avoid severe system failures if one microservice goes down. You know exactly which part of the pipe that fails, and you can therefore issue a fix and redeploy that exact microservice instead of having to bring down the whole monolithical monster of a software project. There are obviously some trade-offs you should be aware of before choosing to go down that path, but my job is to resonate on the jargon while plenty of others has brought up the pros and cons.</p><h4><strong>Monolithic architecture</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xSJZ9bO5X5rQ_K0pbsUGIQ.png" /><figcaption>Monolithic architecture</figcaption></figure><p>The awesome thing about monolithic architectures is that they have proved the test of time. They still work and do their job. Many enterprise architectures are still built upon this method, but their obvious flaw is the complexity of updating them. Not only could they be built on long abandoned frameworks that makes it hard to stay relevant, but people move on and the development team that initially built the big black box is not necessarily the same team that continue developing it further. Thus said, the biggest advantage of a monolithic architecture can also be looked upon as its biggest flaw. As a comparison, in the world of Microservice everything is decoupled and the parts talk to each other through the works of APIs. The beast is divided into much smaller chunks, which are easier for developers to digest.</p><h4><strong>Line of Business (LoB) application</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MSU8sdOxEP3t7im0kjfjKA.png" /><figcaption>Line of Business (LoB) Applications</figcaption></figure><p>A line of business application is an application which is more important for the business than other software. Word, PowerPoint or email for instance, are not LoB applications, but rather tools that aid you in your work day. LoB applications are more directly aligned towards generating revenue for the business. In other word, these application are business critical, or even the generator of revenue in itself. Many companies develop bespoke software for their needs, and those are often the mission critical software that needs to work. For them, that would be a line of business application. Pretty simple explanation for a simple concept that has drifted away from its literal meaning and towards the section of IT buzzwords.</p><h4>Problems when tech choices are made by upper management</h4><p>One problem that often applies in real world scenarios, is when upper management make tech choices without rational reasoning. If the developers are to cope with these choices, management has to convey the reason for why decisions were made. If they don’t, scenarios like the illustration below can occur.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MbtkQNhLR1_EbqtqeWtC9g.png" /><figcaption>Use the right tools for the job</figcaption></figure><p>My point: Use the technologies that make sense. Alternatives might be better in someone else’s eyes, but you still have to evaluate what’s best for a particular scenario or use case. Be critical — there is no silver bullet!</p><p>By continuing this series, I will not only help you understand the core basics of IT jargon that has found its place within the field, but I will also give you facts, tips and tricks. Just look for the light bulb illustration!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*TivU-5eFda7eaIkc2SqNEA.jpeg" /></figure><p>These information snippets are handy if you are a developer, but also useful if you are simply interested in expanding your knowledge. I will link you to some of the many amazing resources that exist, so that you can deep-dive and continue your rapid growth. Some of the resources in the next parts of the series are even created by the Raa Labs team, how cool is that?</p><h4><strong>Going forward…</strong></h4><p>This is where the fun part starts, but we are still in the introduction phase! So, if you cant wait to dive into your track of choice, I suggest you hold tight a bit longer so you grasp all the concepts. This is the first part of the introdcution phase, but we will need one more part before separating into your track of choice.</p><p>We have now introduced the most common ways of carving out overall software architectures and explained some basic terminology.</p><p>We will now dig deeper into what this series is all about: <strong>Mastering the big beast, Domain Driven Design (DDD)</strong>. More complex words will now need to be explained, and daunting principles be uncovered. But don’t worry! We will do our best to <a href="https://en.wikipedia.org/wiki/KISS_principle"><strong>Keep It Simple Stupid (KISS)</strong></a><strong>.</strong></p><h3><strong>Domain Driven Design</strong></h3><p><strong>The follow topics will be discussed and reflected on in this section:</strong></p><p>• What really is Domain Driven Design?</p><p>◦ Domain</p><p>◦ Model</p><p>◦ Ubiquitous language</p><p>◦ Distilling the problem space of DDD</p><p>◦ Bounded context and sub domains</p><p>◦ Distilling the solution space of DDD</p><p>◦ Unpacking Strategic DDD vs Tactical DDD</p><p>Software is made to solve problems, and software written with the DDD mindset doesn’t shy away from that fact. People that write the software however, often dive straight into frameworks and code, missing critical supporting information for the specific problem. Remembering what the code you wrote yesterday actually does can also some times be a struggle. And if you struggle with it, you can bet a new developer also will! Maintainability in development, and writing self-explanatory code can often be difficult and time consuming.</p><p>The people surrounding the team of developers and other stakeholder, often shy away from the development process and does not get involved enough. This can result in a barrier where people talk their own language and the development team doesn’t really understand what they are conveying. And vice-versa…</p><p>This is not how DDD works! Adjusting the «get it done yesterday» mentality is something that DDD tries to solve with its implementation. Before jumping straight into this implementation, you need to understand the gist of DDD and get a deep understanding of what domain that concept is implemented in — while iterating. And that’s exactly what DDD focuses on, the domain. Trying to bring «commonality and collaboration» across the primary focus of the project, is DDD´s mantra. Thus said, not only to raise focus on the domain for non-developers, but the developers as well. Having a specific vision and approach for dealing with inconsistencies around a project is something DDD can help manage with its ever increasing focus on the domain at hand. So what really is a domain and why is the domain so important for DDD other than having the word «domain» in its name? Let’s find out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ltczfhbi7-pdwyiVMIzEcg.jpeg" /><figcaption>Classical challenge in DDD space</figcaption></figure><h4><strong>What really is Domain Driven Design?</strong></h4><p><strong>But first… </strong>I’ll be honest, I read the book from Eric Evans and it was quite a read. Super comprehensive and, quite frankly, difficult to comprehend. So instead of giving up on learning DDD, I found help elsewhere. InfoQ had a short summarized version based on «the blue book» called «<a href="https://www.infoq.com/minibooks/domain-driven-design-quickly/">Domain Driven Design Quickly</a>». I read it, and I instantly loved it. Another inspiration is the book named “Pattern, Principles, and Practices of Domain-Driven Design” by Scott Millett with Nick Tune. My inspiration is based upon these two books and examples are crafted from those books. If you are interested in learning even more about DDD, I recommend you read these to further expand your knowledge on the subject. Keep in mind, these books are more in-depth than what we are to cover in this series. So, if you would like to stay high-level on the topic, keep on reading!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*ZdDqEt0TQuVA97FOjEQo9Q.png" /><figcaption>Eric Evans Domain Driven Design overview</figcaption></figure><p>Looking at the illustration above, you might feel a bit baffled. But don’t worry, my aim is to break down the barrier that prevents us from understanding what the picture really illustrates. The figure is from <a href="https://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215">Eric Evans book</a>, and gives an overview of Domain Driven Design. For us to understand the topic, we will have to divide the figure into small easily digestible subtopics and work our way up from there.</p><p>Let’s start with understanding what a domain is.</p><h4><strong>Domain</strong></h4><p>A domain is the problem space that should be solved by designing a software.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c_CBWoviOxe_RTx8W1zifA.png" /><figcaption>Shifting focus</figcaption></figure><p>A domain is often a complex collection of variables in a set environment that can shrink, expand and evolve — depending on how you define the boundaries. For complex environments you can’t sit down and write code without understanding the essence of it.</p><p>Consider the metaphor of a ship manufacturer. A ship can consist of hundreds of thousands of parts, and the workers working on the development of the ship, don’t have a full overview of all the manufacturing that goes into building a ship because of its share scale. Workers focus on one particular area of the ship and complete that while other workers are working on other parts of the ship in parallel. In other words, progress is happening simultaneously. The worker that is working on the rear of the ship, doesn’t need to know exactly how the progress is going on in the front of the ship because it’s out of his scope and will not impact the work he is doing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ns4psbF89yfaZzc22FawWA.jpeg" /><figcaption>Ship manufacturer</figcaption></figure><p>There are however some people that have the job of knowing the exact status of the development of the ship from a bigger picture. Those people have a better overview of the full progress but doesn’t need to know the exact implementation as particular knowledge is required. As long as the work is being done and he can see the overall progress, he is happy. Now we jumped from people working on the nitty gritty details of the implementation, and up to the project leader that has an overview of the overall progress. In between these two roles, there are plenty more. Each level we go up or down, new knowledge is required to understand the boundaries of the work being done and how to do it.</p><p>Software is similar to the complexity that a ship manufacturer sees. If we were to craft software for ship manufacturing, we would have to know much more about the ship manufacturing domain. There will be tons of requirements that needs to be met for the ship, and without having a good understanding of the domain, it is not possible to write good ship manufacturing software. In trivial cases, you can jump straight into code but in complex environments, a lot of consideration must be made.</p><p>So how do you get to know the domain? By <strong>involving the specialists</strong>. The domain experts. By involving the people who actually have the knowledge about why we are making the decisions that we do. These are the people that will transfer knowledge that eventually will reflect the core elements of the domain to yield good ship manufacturing software. To enhance a domain and plant the roots of bespoke software in it, you have to understand it and model it.</p><p>So now that we understand what a domain is, how do we express it in code? That’s a particular subject within the back-end track of this series. In order to get a better overview of DDD in general, there are many more topics that we need to address, and keeping the explanations short and concise will benefit us going forward. We still haven’t modeled the domain which is essential in order to implement it properly. So, what do we mean by modeling a domain?</p><h4><strong>Model</strong></h4><p>The three-point summary of DDD depends on the definition of the terms:</p><p>• Focus on the core domain</p><p>• Explore models in a creative collaboration of domain practitioners and software practitioners</p><p>• Speak a ubiquitous language within an explicitly bounded context</p><p>These bullet points are straight out of <a href="https://www.amazon.com/Domain-Driven-Design-Reference-Definitions-Summaries/dp/1457501198/ref=pd_sbs_14_t_0/144-3635015-0442100?_encoding=UTF8&amp;pd_rd_i=1457501198&amp;pd_rd_r=66fe0779-a389-484e-b428-d2f60f92f2d6&amp;pd_rd_w=X8wD6&amp;pd_rd_wg=kH4iW&amp;pf_rd_p=5cfcfe89-300f-47d2-b1ad-a4e27203a02a&amp;pf_rd_r=9188MH9EV3D225FPMYB7&amp;psc=1&amp;refRID=9188MH9EV3D225FPMYB7">Eric Evans DDD reference booklet</a>. We have elaborated on the first term and will explore the second one.</p><p>A model is, simply put, a representation or abstraction of the target domain. In order to map a domain in an easy and understandable manner, we need to organize information, systematize it and divide it into smaller blocks as our thinking process is synthesized into this model. And sometimes, you need to exclude parts of the domain because it gets too vast and complex. For now, this will be our elaboration of the model. Going forward, we will give concrete examples and visualize how a model can look like, extracting the key elements of the domain into an abstraction.</p><p>Let’s revisit the model representation later, and currently keep up the pace and dive straight into the third bullet point from the three-point summary. This next topic on the agenda is critical to understand in order to move forward, and is looked upon as one of the core building blocks of DDD.</p><h4><strong>Ubiquitous language</strong></h4><p>A big part of DDD is to keep all communication in a language that makes sense for the domain so that all stakeholders fully understand each other and can work efficiently. In order to model a domain, you need to communicate in a certain way. So what do we mean by that? Are we talking about speaking in English or French? Well, not really. The idea is to define a language that developers can implement into code so that its understandable from the outside. Of course, you have to use an actual language as the core foundation for communication, but we mentioned earlier that developers need to implement the domain into something tangible as code. This is where the developers would come up with class names, variables, etc. in their code. In order for the developer to come up with good and well defined variables and class names that makes sense, the developer needs to write them as simple as possible while keeping it domain specific so that if a new developer comes in, he should in theory understand and make sense of the domain while understanding what the code does. This all sounds well and good, but I did write «in theory» on purpose, because practically, it is not easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q2iW3T3ATd8FtijlIBCvEQ.png" /><figcaption>Confusing words in different contexts</figcaption></figure><p>You might be wondering why this is so difficult. Well, everyone has their own communication style, and mixed into that style are ideas and personal understandings of subjects that might not be the same for others. If you look at the word clouds above, the experts in their respective domain has their own way of communication. On the left, you have a ship manufacturer that is talking about hydraulics and forging and such. On the other side, you have developers talking about their domain. When coming up with a domain model you have to communicate with domain experts. These experts will use their jargon while developers will have their own language tuned for discussing the domain in terms of design. If there is a barrier of understanding between the implementing party and the key stakeholders, the domain implementation will absolutely suffer from this. If the day-to-day discussion is disconnected from the terminology embedded in the code, transient information expressed from domain experts might not get encapsulated properly in the implementation. Coming up with a ubiquitous language for communication and implementation is therefore one of the most important parts of the project in order to make it succeed.</p><p>In short, <strong>learn the domain!</strong> And the process of doing that, is to not impose a new language. Rather embrace the domain and make an understanding of it. Recognize that a change in the language is a change in the model. Iron out difficulties by experimenting with alternative expressions, which reflects alternative models. Then refactor code, renaming classes, methods, and modules to conform to the new model. (Eric Evans, June 2014)</p><p><a href="https://www.youtube.com/watch?v=Ru2T4fu3bGQ">Robert Smallshire</a> has a short and concise way of describing the ubiquitous language. Some of the key bullet points he boiled the ubiquitous language down to during a presentation at the euro python conference in Edinburgh, were the following:</p><p>• Context dependent</p><p>• Valid within limits of applicability</p><p>• Used by a community of problem domain experts</p><p>• Shared meaning</p><p>• Single meaning</p><p>• Expressed in the software model</p><p>• Reduces distance between problem and solution</p><p>I think Robert´s take on it pretty much sums up what the ubiquitous language is all about. If you want to watch his presentation, I have linked it in the references section in the bottom of this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bBIMtTVhw1Ay0bLLPpz4Bw.jpeg" /><figcaption>When the developer is left out, confusion appears</figcaption></figure><h4>Domain storytelling</h4><p>Domain Storytelling is a <strong>knowledge crunching</strong> technique. The people who participate in a Domain Storytelling workshop will get new insights into the domain. The resulting Domain Stories express their shared understanding. Other ways to build domain knowledge include scenarios (<a href="https://www.amazon.com/Domain-Driven-Design-Distilled-Vaughn-Vernon/dp/0134434420">Vaughn Vernon</a>) and scenario exploring(<a href="https://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215">Eric Evans</a>). Domain Stories help you to come up with scenarios and to visualize them. I Recommend reading the book from Stefan Hofer and Henning Schwentner on <a href="https://leanpub.com/domainstorytelling">Domain Storytelling</a>. The book covers the gist of domain storytelling and illustrates it with easy-to-grasp examples. One of their case studies which illustrates the concept, is based on a chain of Cinemas. Imagine if you are asked to develop an app that allow their customers to make reservations and buy electronic tickets. To familiarize ourselves with the domain, we set up a Domain Storytelling workshop. After discussions back and forth, you will eventually end up with a use case diagram that illustrates the ticket system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1SBlYKxnJ0gzQPjgNsSZxg.jpeg" /><figcaption>Use case diagram for Cinema application</figcaption></figure><p>From the illustration above, you seem to have covered all the features that should be implemented into the cinema app based on the illustrated use case diagram which evolved from the domain storytelling session. But you keep on discussing and it turns out that the ticket system actually has the ability to issue tickets directly back to the customer through the app. This was not discovered at first, but as it turns out, the ticket system can issue QR-based tickets; the user will get the tickets instantly — making it much easier for the customer not having to manually collect the tickets from the cashier at arrival. This is new information! Clearly this should be illustrated as well, so we update the use case diagram to look as following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-fg5q-cvtUiBFScMUBk9A.jpeg" /><figcaption>Revised use case diagram for Ciname application</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*p44q9LJ01ErjzFN1d4fUUw.jpeg" /><figcaption><a href="https://github.com/WPS/domain-story-modeler">https://github.com/WPS/domain-story-modeler</a></figcaption></figure><p>By having knowledge crunching sessions like this, you can really make sure you meet all requirements that are set. It is easy to get confused by big and complex domains, but using techniques like domain storytelling will help you break down the problem into simple parts like we did in the trivial example above.</p><h4><strong>Distilling the problem space of DDD</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lac3U4Goc945TO3KxLE58A.png" /><figcaption>The problem space of Domain Driven Design</figcaption></figure><p>The figure above is a blueprint replica of how <a href="https://www.amazon.com/Patterns-Principles-Practices-Domain-Driven-Design/dp/1118714709">Scott Millett and Nick Tune</a> illustrates <strong>the problem space</strong> of DDD. Already from the looks of it, there are a couple of new terms that we are not familiar with. Let’s discuss these in the next section, but first get an overview of what we are looking at.</p><p>The blueprint starts with understanding the problem domain and business wish. From there, the domain experts and the development team sit together and understand the language of the domain — the ubiquitous language. Once the language is set and everyone are on the same level, they crunch through the domain knowledge. At this point, the development team should be ready to implement the distilled domain knowledge into code. They separate the code into appropriate sub domains with appropriate models. Hopefully, the development team has understood the domain vision as the domain experts envisioned it. Focusing on the core domain is critical as this is the main reason for the system being built.</p><h4><strong>Bounded context and sub domains</strong></h4><p>A bounded context defines the limits of applicability for a ubiquitous language. Since domains often can become very complex and big, it is a good approach to distill the domain into smaller and separate models. So instead of having one big model for the domain, you have many smaller ones that are properly defined and has specific boundaries of what they are to encapsulate. Many larger domains will have multiple bounded contexts within them. So, the meaning of specific words will therefore be determined based on which bounded context it belongs to. Therefore, we can say that a words meaning is easily understood in a context. The bounded context is a description of the boundaries that exists within a particular model.</p><p>Let me give you an example. Consider the figure below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qsTsB0-xwGDK461_CgIKBQ.jpeg" /><figcaption>Words have different meanings depending on their context origin</figcaption></figure><p>As you can see, these words clearly point to different things depending on the context, even though they are spelled the same way. These words can easily create confusion, unless you know the model you are referring to and which bounded context we are talking about. Maintaining a strong decoupling between different bounded contexts makes large systems simpler.</p><p>The word Serve means something totally different in a restaurant context compared to a Tennis related context. Set and Pour are other examples as well.</p><p><a href="https://www.developer.com/open/domain-driven-design-understanding-bounded-context-and-the-context-map.html">Alireza</a> from developer.com explains the concept of sub domains and how it differs from bounded contexts in a simple digestible way. What’s important to know is that sub domains are different from bounded contexts.</p><p>A large problem domain can be decomposed into sub domains to manage complexity and separate important parts from the rest of the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OW9heuqFOqIyK7c6IFgHpA.jpeg" /><figcaption>Different types of sub domains</figcaption></figure><p>There are three kinds of sub domains that we here differentiate based on how much competitive advantage it yields:</p><ul><li><strong>Core domain: </strong>The most important part of the system, the reason for the success. This will give you competitive advantage, so focus on this and make this as good as possible.</li><li><strong>Generic domain:</strong> This is not the core, but the core depends on it. e.g. email sending service, monitoring service and such. Try to re-use existing parts and don’t spend too much time on these systems.</li><li><strong>Supporting domain: </strong>«Extra» domains that help to support the core but does not provide any competitive advantage. Not recommended to invest heavily on but still needed in order to succeed in the core domain. Maybe even outsourcing could be a possibility here?</li></ul><p>From the bullet points above, you can clearly see that some domain types are more important than others. In a bigger domain; you usually split the domain into smaller domains. Within the context of a sub domain, there can exist an independent model for each sub domain. This is important to know as there does not only have to be one model, but many models for each domain. Unlike a sub domain, a bounded context is a concrete technical implementation that enforces boundaries between models within an application.</p><h4>How to focus on the core domain</h4><p>Treating large problems as one huge problem, often results in failure. Common practice is to partition the large problem domain into smaller sub domains to manage complexity and separate important parts from the rest. In the domain of butchery, a pig is sliced into much smaller pieces much like a problem space. If understanding of the sub domains is acquired, you can easily break down the problem space. <a href="https://www.amazon.com/Patterns-Principles-Practices-Domain-Driven-Design/dp/1118714709">(Scott Millett and Nick Tune)</a> has a very valid point about sub domains.</p><blockquote>Sub domains are abstract concepts; don’t get sub domains confused with the organizational structure of a company. Sub domains represent areas of capability, define business processes, and represent the functionality of a system.</blockquote><p>By attacking the problem space in this manner, you should be able to more easily conquer it and reduce complexity of the larger problem.</p><p>I highly recommend reading their book as it clearly illustrates these concepts, and many of the figures in this series is re-created based on the originals from Scott and Nick.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ql4H0vBxocbCmim2Uux84w.png" /><figcaption>A pig marked with its cuts</figcaption></figure><h4>Distilling a problem domain as an example</h4><p>Let’s consider the domain model of an online auction website. As we might expect, there are plenty of elements within an online auction, and a lot of these will be unique for the domain and specific business.<br>Starting point:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zXa4hw1MA20GCNIBMt7GoQ.jpeg" /></figure><p>Now we need to separate the domain into smaller partitions based on what makes sense. Membership within an auction site takes care of the registration process. Seller is another partition which takes care of all behaviour related to seller activity. Auction is the area of the problem that deals with managing the timing of auctions and dealing with bid activity. Listings takes care of listings on the auction site. Finally, we have the dispute resolution which handles all disputes between members and sellers. It is not written in stone that a auction site has all of these parts, maybe some don’t have a system for dispute resolution, or maybe some have others which I havent listed. For the sake of the example, let us use the aforementioned as a foundation as we classify each individual separation into subdomains.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2vLXUDIhwuB6SLIp5WZlNw.jpeg" /></figure><p>At this point, you have already distilled knowledge from domain experts and revealed the different parts of the problem. We know that some parts are unique, and some are dependent on each other. Now comes the time to classify each part into the appropriate partitions called subdomains.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhot7hJTOCY61cPw9mvpKA.jpeg" /></figure><p><strong>What would be the deciding factors for the success of our auction site?</strong> Those vital parts should be classified as the core domains. It is worth mentioning that you don’t only need to have one core domain but can have many if it makes sense.</p><p>The core domains for the auction site is seller and the auction. The seller domain contains ratings for seller and the domain logic needed in order to determine the seller fees. The auction core domain however, consists of mechanisms to handle biddings and running the auctions. These are important. The membership domain and listing domain are supportive for the core domains by providing possibilities to create accounts and find items for sale. The dispute resolution domain is generic in the sense that it can be served with off-the-shelf software. An example of this could be a ticketing system.</p><p>The main idea is to know where to invest, where to put your efforts and what parts you can outsource and get from elsewhere. All these decisions that outlines the domain into subdomains are results from knowledge-crunching sessions which not only the domain experts are part of, but also the developers to help them grasp and understand the domain in a collaborative effort.</p><p>These subdomains will help you shape a solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DqrdQqyJFdk_fbgG4v7t4A.jpeg" /><figcaption>Domain separation illustrated</figcaption></figure><p>Two systems have resulted from the process. One part of the domain can be fulfilled by an off-the-shelf package while the core and supporting domains have been built using a custom web application.</p><h4>What if I don’t have a core domain?</h4><p>There are many reasons that businesses build rather than buy software. If you can do it cheaper, faster, or smarter then it’s a good candidate for a custom build.</p><p><strong>Distilling the solution space of DDD</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yRPxbcSzmcSI4kllk-Wl0g.jpeg" /><figcaption>The solution space of Domain Driven Design</figcaption></figure><p>The solution space covers patterns that can shape the architecture of your applications and make it easier to manage. DDD is architecturally agnostic in that there is no single architectural style you must follow to implement it.</p><h3>Mismatch between models</h3><p>How does mismatch between models occur? And why is it so important to remedy this? I mentioned that there is no single architectural style you must follow in order to implement DDD as it is architecturally agnostic. There is however some architectures that historically haven’t aligned as much towards the DDD mindset as others. The usual way of crafting a monolithic architecture leans towards a waterfall approach where you plan the whole system upfront. Diving straight into UML sketches of the entire solution is not always the best way of solving things. After the domain experts and business analysts create the analysis model and hand it over to the developers, the analysis and code models can diverge from each other if the development team is not involved in domain knowledge crunching.</p><p>As developers start to implement the analysis model in code, they often find a mismatch between the high-level artefact produced by architects and the reality of building the system. Models need to be isolated and defined within an explicit context in order to stay pure and focused. However, at this stage there is often no feedback loop for developers to talk to the business and architects, so the analysis model can be updated, and their input enacted. Instead, the developers diverge from the analysis model, and their implementation often overlooks important and descriptive domain terms and concepts that would have provided deeper insight and understanding of the domain <a href="https://www.amazon.com/Patterns-Principles-Practices-Domain-Driven-Design/dp/1118714709">(Scott Millett and Nick Tune)</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BqSu-tNvm55lkQSsatddGA.jpeg" /><figcaption>Important concepts get lost and misinterpreted when there isn’t a joint effort on collaboration between the two sides. Proper ubiquitous language will help the two models to stay aligned. This is where the added importance of a feedback loop takes place.</figcaption></figure><p>Having a more unified team approach suggests leaning towards collaboration efforts far more important when doing DDD than any other practice. Having a constant feedback loop enables the discovery of important concepts that doesn’t get misinterpreted as the ubiquitous language is in place. These two models will also be bound to each other because of the ubiquitous language. A change in the code will and should also reflect a change in the analysis model because of the importance of synergy between those two.</p><p>So how can you potentially solve the problem with a DDD implementation, and how do you get to an architecture? One tool is to come up with a Context map through the work of an <a href="https://en.wikipedia.org/wiki/Event_storming">Event Storming </a>Session! We will learn more about event storming and context map in a second. First, we need to unpack the strategic elements of DDD.</p><h4>Unpacking Strategic DDD vs Tactical DDD</h4><p>Remember the big complicated image with all the boxes earlier on which we didn’t understand? Now is the time to split it up into two parts, respectively into Strategic and Tactical sides. By splitting it up, we can define certain boundaries and tackle elements that are relevant for that part. Strategic patterns shape the solution, while tactical patterns are used to implement a rich domain model.</p><p>But why does splitting it up make sense?</p><p><a href="https://medium.com/tacta/a-decade-of-ddd-cqrs-and-event-sourcing-74edc8211039">Anes Hasičić </a>summarized this pretty well in a Medium post which I highly recommend to read. We haven’t reached all of the concepts mentioned in the post below, but will eventually get there.</p><p><a href="https://medium.com/tacta/a-decade-of-ddd-cqrs-and-event-sourcing-74edc8211039">A Decade of DDD, CQRS and Event Sourcing</a></p><blockquote>Evans has earlier stated that he regrets putting the strategic patterns way back at the end of the book, which probably resulted in many people giving more importance to the tactical patterns because they come first or even worse, they get so caught up in the intricate implementation details of tactical patterns, they don’t even get to the most important part of the book.</blockquote><blockquote>The thing to take away is that building blocks provide you the tools to implement DDD, but you should give much more focus to strategic patterns, even more so because tactical patterns/building blocks will continue to evolve, some will become obsolete, new ones will be added (e.g. Domain Events).</blockquote><p>Let’s start by looking at the strategic side before we dive into the tactical side.</p><h4>Strategic DDD</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*5es7d_Sxvsn73BEO2ZEBFQ.png" /><figcaption>Strategic side of Domain Driven Design</figcaption></figure><p>Looking at the elements from the figure, we have already covered some of them. Elements like Continuous Integration, Big Ball of Mud, Context Map are worth talking more about before we close the strategic chapter.</p><h4>Continuous Integration</h4><p>Continuous Integration (CI) is a practice for developers, where it aims to have a shared code repository and push commits to in a high frequency. Based on these commits from the developers, bigger build and release pipelines trigger for continuous deployment (CD) of the application. This is an automatic process which checks integrity of the code and can help in detecting problems that might have been introduced during the latest commits. DDD heavily emphasizes on this practice, hence the reference in the strategic DDD figure. Some organizations may have trouble with these practices, particularly if their experience is largely tied to less-flexible development models, such as the waterfall model or the like. (<a href="https://airbrake.io/blog/software-design/domain-driven-design">Andew Powell-Morse)</a></p><p>Below is an article I wrote on the topic of DevOps which consists of elements like CI/CD.</p><p><a href="https://medium.com/raa-labs/creating-a-pipeline-in-azure-devops-to-build-and-publish-python-packages-artifacts-ea2f99410e6c">Creating a pipeline in Azure DevOps to build and publish python packages/artifacts</a></p><h4>Big Ball of Mud (BBoM)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*pmdADmyWg6Ic6Z9MsUJu2Q.png" /><figcaption>A big ball of mud</figcaption></figure><blockquote><em>A Big Ball of Mud is a haphazardly structured, sprawling, sloppy, duct-tape-and-baling-wire, spaghetti-code jungle. These systems show unmistakable signs of unregulated growth, and repeated, expedient repair. Information is shared promiscuously among distant elements of the system, often to the point where nearly all the important information becomes global or duplicated.</em></blockquote><blockquote><em>The overall structure of the system may never have been well defined. <br>— </em><a href="http://www.laputan.org/mud/"><em>Brian Foote and Joseph Yoder, Big Ball of Mud</em></a></blockquote><p>What do you do if you are dealing with a legacy system, a big ball of mud? How do you get a taste of DDD there (assuming you still can employ the iterative development approach, and have access to domain experts)?</p><p>Well, just because the legacy system i.e. “the big ball of mud” exists, it does not mean you have to keep cramping it with new features, but rather, employ your context mapping techniques here. Draw a line around it and say, “this is my big ball of mud”, and after that draw a line around your new service and treat it as a separate bounded context.</p><p>As Evans puts it, it’s probably inevitable that your service will get enclosed by the big ball of mud eventually (since it will eat almost anything), but at least you had a nice run for a time. <a href="https://tacta.io/a-decade-of-ddd-cqrs-and-event-sourcing/">(<em>Anes Hasičić)</em></a></p><h4><strong>Context mapping</strong></h4><p><em>TLDR; The boundaries defined with integration points illustrated.</em></p><p>How do you identify the existing problem space? And how do you then split the domain into sub domains and create bounded contexts? Through the work of event storming! You will learn more about event storming in the next upcoming topic, but through the work of event storming is a resulted context map which essentially maps the existing terrain. But why is it important?</p><p>In large and complex applications, multiple models in context collaborate to fulfil the requirements and behaviours of a system. A single team may not own all the various sub components of a system, some will be existing legacy code that is the responsibility of a different team, and other components will be provided by third parties that will have no knowledge of the clients that will consume its functionality. Teams that don’t have a good understanding of the different contexts within a system, and their relationships to one another, run the risk of compromising the models at play when integrating bounded contexts. Lines between models can become blurred resulting in a Big Ball of Mud if teams don’t explicitly map and understand relationships between contexts.<a href="https://www.amazon.com/Patterns-Principles-Practices-Domain-Driven-Design/dp/1118714709"> (Scott Millett and Nick Tune)</a></p><p>You can look at the context map as the defining visualization of how the boundaries are defined for your project situation, and where boundaries have been separated into different contexts. <br>A context map is <strong>not(!)</strong> a highly detailed document created in some kind of enterprise architecture tool, it is a high-level, hand drawn diagram that communicates a holistic picture of the contexts in play. A context map should be simple enough to be understood by domain experts and development teams alike. As well as clearly labelling the contexts the teams understand, the diagram should also show areas of the system that are not well understood to reflect the messy and often unintelligible reality of the codebase.<a href="https://www.amazon.com/Patterns-Principles-Practices-Domain-Driven-Design/dp/1118714709"> (Scott Millett and Nick Tune)</a></p><p>This might seem a bit confusing, let me give you an example of a context map:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CVj3injPJycR8fxMKr-Kpw.jpeg" /><figcaption>An example of a context map</figcaption></figure><p>The figure above illustrates a context map. You can see that there is an Anti-Corruption Layer in place which protects the HR context from the recruitment context. This is because the recruitment context is a third party which is prone to other forces which shouldn’t affect our prime contexts. We will dig deeper into ACL (Anti Corruption Layer) further down.</p><p>It is extremely important that context maps reflect reality, showing the code in the present state rather than an ideal future state. Context maps doesn’t need to show the detail of a model; instead, they must <strong>demonstrate the integration points and the flow of data between bounded contexts</strong>. We still haven’t illustrated the relationship status on the context map other than connection points, so learning more about how we can illustrate the flow of relationship is the next topic.</p><h4>Upstream/Downstream relationship</h4><p>A very important factor in DDD context maps, is the direction of the relationship between two contexts. DDD uses the terms upstream or downstream: an upstream context will influence the downstream counterpart while the opposite might not be true. These are often shortened to the letter d and u respectively. This might apply to code (libraries depending on one another) but also on less technical factors such as schedule or responsiveness to external requests. In the example below, you have a context map which illustrates a Personal Finance Management Application that talks to an online banking service through an API. So, in this case, the PFM application is the downstream, and the online banking service is the up streamer. We will go more in depth around the relationship further down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6S_iBkY2WySBeISWppp81g.jpeg" /></figure><p>A good context map would give you a picture of the odds against you. You might know if the organization is — consciously or not — working against your project’s success, even before the project starts.</p><p>InfoQ has an easy to digest example on how a context map could look like for a web-based Personal Finance Management Application (PFM). The PFM is made to track budgets, manage banking accounts, stocks and such. In the application, the term “Account” might have different meanings. In the banking context, an account is looked upon as “container of money”. In another context however, take the web application context; the account has a different meaning. In the banking context, you expect attributes like balance, account number, IBAN and such. For the web application you have attributes related to authentication and user credentials. In other words, not the same concept. At this point, we meet the case of ambiguity related to the term “account”. Now we are starting to see the meaning of the ubiquitous language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UrmYDXq__EIvHxVcJUbdhg.jpeg" /></figure><p>So, when we have ambiguities like the case above, we need a tool to distil the domain into smaller more tangible bounded contexts to make sure that the whole team is aware of the existence of the different concepts. This is where context map shines. As mentioned earlier, context maps are NOT super high-fidelity illustrations, but more sketches that shows that contexts can be a bit fluffy and hard to define, so having a “rough” look is needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6mdwx33lFaEWIZwT38IT6Q.jpeg" /></figure><h4>Unified Modeling Language (UML)</h4><p>UML is an industry standard in the space of data related modelling. With UML diagrams, you can easily sketch out your whole system in high details. In programming and project engineering, UML is widely used to draw class-diagrams that shows the attributes, methods, parameters and such. This diagram is a “visual representation” of the class that the developer is to implement. So, using UML to showcase underlying concepts will simplify and bridge the abstraction between a context map, model and code. UML is a language for describing software systems. It’s software first. Domain-Driven Design is a focus on understanding the actual concepts of domain experts. So, this is people first. But these are just tools and choosing one does not indirectly invalidate the other.</p><p>As Martin Fowler said:</p><blockquote>“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”</blockquote><p>That’s much more likely to happen if programmers start with the existing <em>human</em> understanding of the situation. So UML can therefore be used to express code in more tangible and illustrative ways than just huge amounts of text on a screen.</p><p>Let’s draw a simple class representation for Banking Account and further delve into the concept of context maps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bb-eUZQ3ToWiwzzYmpqkLg.jpeg" /><figcaption>UML example</figcaption></figure><h4>Modeling the same concept</h4><p>So, what happens when the concept is the same, but used in multiple ways? Consider the banking account class illustrated above. Some PFM apps allows us to manage payments, usually keeping a Payee registry. In this case, a payee might be associated with one or more banking accounts. But for this scenario, we won’t know anything about the internals of the payee banking account, nor can we do any operations on the banking account… Does it make sense to model the Payee account together with the Banking Account class we just defined?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J-ARnoTPRJITamp4w0Ak-Q.jpeg" /></figure><p>From a real world scenario, it might be that our payees account is in the same physical bank as our banking account, but we are not supposed to issue any operation on the payee banking account, or to track anything on it. So conceptually, it doesn’t make sense. This is a simple example of <strong>two different contexts within the same application</strong> where <strong>modelling them separately</strong> makes sense. We just modeled the same domain concept in two different ways as they were calling for distinct uses. The BankingAccount might still be a class that allows us to perform (or track) specific operation (such as deposit or withdraw) while a separate class PayeeAccount could possibly have some data in common with BankingAccount (such as the accountNumber), but a simpler model and a definitely different behavior (we shouldn’t be able to access the payees’ balance, for example)<a href="https://www.infoq.com/articles/ddd-contextmapping/">(InfoQ)</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ju3ijLhWqArXrUT_WP3wtA.jpeg" /></figure><p>This might sound obvious to some, but it’s not. When working on a class diagram, or a UML modelling tool you might really easily start modelling a Payee that has a bankingAccount attribute and think “I’ve already a class for that”. The <a href="http://en.wikipedia.org/wiki/Ivan_Pavlov">pavlovian</a> attempt to get rid of code duplication might do more harm than good, sometimes(<a href="https://www.infoq.com/articles/ddd-contextmapping/">InfoQ</a>).</p><p>As long as our domain knowledge increases, the context map evolves! Now, we just split the PFM application into two separate contexts; Banking and Expense tracking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*39YR-gfTwZckLqYXkK38Yw.jpeg" /></figure><h4>Elaborating on a context map</h4><p>Since there is a dependency involved on an external party, the relationship between two contexts can become brittle. Either, the external party from our perspective; can choose to listen to our demands and develop software that fits towards our requirements, or they can create something that the using party (us in this case) has to conform with. Since the PFM application is interacting with the online banking service through an API, we need some kind of protection against changes coming from the upstream context. This will help us to preserve the integrity of the banking context. The most common practice to do so, is to implement something called an Anti Corruption Layer (ACL). This puts up a barrier at the tip of the context that the stream has to go through before getting accepted into our PFM context. In the ACL, an explicit translation is happening at the code level between the two contexts. An example could be to transform the incoming object from the legacy model to the domain object in your main application’s model. This works as a place to manage all the subtle differences between the models on both ends. Microsoft has a pretty <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/anti-corruption-layer">well defined guide on ACL</a>. I recommend reading that if you are to implement this. There might also be an idea to put up an ACL between your main context and the potential big ball of mud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IK6zGf0DdgXx46sgwdrkdg.jpeg" /></figure><p>There is also going to be other contexts in a bigger picture within the organization, that are not external. These contexts might be maintained by other people and are subject to different forces. We might need to interact with these as well. If Banking and Expense tracking were to be maintained by different teams, they’re likely to be in a partnership relation: they’re both developed towards a common goal (and upstream-downstream doesn’t make much sense since they’re on the same level). If Web User Profiling is achieved with an external module, we’re probably going to use it “as-is”, meaning that we’re downstream and Conformist, towards Web User Profiling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ceDCP25XS2lWU8X_AFf6_g.jpeg" /></figure><p>Let’s suppose now our PFM application grew larger, and another team (Team B) has been assigned to work with us (we’re obviously Team A) on a new trading module of the same application. Team B might be in a different room, building, city, company or country and is fully dedicated to the trading area. In the example below, Team A shares some of the code with Team B, even if they tend to work on separate portions of the code base. Eventually, team B writes some class (A in Figure 12 below) that implements functionalities needed by team B, that were already available in class A<a href="https://www.infoq.com/articles/ddd-contextmapping/">(InfoQ)</a>.</p><p>That’s code duplication, the root of all evil! In a single, well defined, bounded context, this is definitely true. But for some reason this does happen in almost every non trivial project. This is normally a sign that there are probably not-so-well-separated contexts in play<a href="https://www.infoq.com/articles/ddd-contextmapping/">(InfoQ)</a>.</p><p>A Context Map reflects our current level of understanding of the whole system and will be updated as long as we learn something more, or the environment changes. Currently, we don’t know exactly what’s going on, and this is “our current level of understanding”. So, since we are not 100% sure about the Trading part of the domain, we might need put up a sign illustrating this. This is illustrated as the overlapping round element that partially overlaps with our PFM application and has an exclamation mark on the intersection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*803L8GtO-ErS3HBa7XDfOQ.jpeg" /><figcaption>An example of a complete context map illustrated</figcaption></figure><p>As long as we gather more information, the map will become clearer. As mentioned before, simply acknowledging that there are different models in play within our application and that model integrity can be preserved only inside a well-defined bounded context, provides a lot of value to our domain modelling perspective. Many models lose integrity as they grow, context mapping helps a lot in this sense(<a href="https://www.infoq.com/articles/ddd-contextmapping/">InfoQ</a>).</p><h4><strong>Event storming</strong></h4><p><em>TLDR; Process for landing on a vision</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UvwtV9P5MYdxz5RrGGktXg.jpeg" /><figcaption>Event storming illustrated</figcaption></figure><p>Event storming as an actual facilitated workshop where there are many participants, including developers, domain experts and others. The facilitators role is to keep the group of people engaged and aligned towards the same goal:<strong> modelling the domain</strong>. There is a lot of back and forth in this session, and it is recommended that the group of people are familiar with the concepts of DDD before execution. Event storming is a tool within the DDD toolbox and should be used as a tool. There are certain boundaries that are defined on how to conduct an event storming session. <a href="https://www.eventstorming.com/book/">Aberto Brandolini</a> has written a book on this topic and is recommended for those who wants to learn more about how you conduct an event storming session.</p><p><a href="https://philippe.bourgau.net/drafting-a-functional-architecture-vision-with-ddd-event-storming-part-1/">Philippe Bougau</a> has also created a fantastic ongoing guide on how to conduct Event storming. It’s short and concise and explains the core concepts of it. Highly recommended to read if you don’t feel like diving head-first into tons of content.</p><h4>Tactical DDD</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*wddTYIRy3kh9cQZkzLerMQ.png" /><figcaption>Tactical side of Domain Driven Design (DDD)</figcaption></figure><p>The tactical parts of the DDD chart, should give you building blocks in order to help you implement a successful implementation. These are all big topics that are more technical than what we have covered in this stage, but we will need to cover these in the next part of the series.</p><p><strong>How are the two parts of DDD connected?</strong></p><p>Through ubiquitous language — the binding between the code and the analysis model.</p><p>At this point, you should have enough information to grasp the concepts of what is happening in the DDD illustration below. If you can’t make an educated guess of the flow, I suggest you scroll up and read the topics discussed once more before jumping into the next stage of the series as we will cover more concepts that might seem confusing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWAIlHl78HVd04uRw5wknQ.jpeg" /><figcaption>The concepts and overview of Domain Driven Design (DDD) illustrated</figcaption></figure><h3>When to use DDD</h3><p>When are you supposed to leverage the power of Domain Driven Design? That is a good question that is difficult to give one answer to as every software project is different. Even literature disagrees with each other. Some say you can apply DDD principles into every project, whilst others tend to use DDD in projects where business logic is rather complex and convoluted. My take on this is that you have to weigh the advantages to the disadvantages for your particular project. In some cases, DDD would be a great fit, but in others not, especially where the applications have marginal domain complexity, but conversely have a great deal of technical complexity. Andrew Powell-Morse has a good summary on the topic. Since DDD so heavily emphasizes the need for (and importance of) domain experts to generate the proper ubiquitous language and then domain model on which the project is based, a project that is incredibly technically complex may be challenging for domain experts to grasp, causing problems down the line, perhaps when technical requirements or limitations were not fully understood by all members of the team (<a href="https://airbrake.io/blog/software-design/domain-driven-design">Andrew Powell-Morse</a>).</p><p>I sketched this simple drawing to represent where I feel DDD can be used, although it is not a requirement:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7hfGxerrsQbpL7Oa15JfbQ.jpeg" /><figcaption>Matrix of when to use Domain Driven Design principles</figcaption></figure><h3>Going forward</h3><p>Wow, that was exhausting! A lot of information went into this section of the series. I’m glad you are still going strong. Let’s continue on that note and jump into other relevant subtopics that makes sense to elaborate on.</p><ul><li>Tactical DDD building blocks</li><li>Event sourcing</li><li>CQRS</li><li>DDD frameworks</li></ul><p>These are all big topics. To not risk writing a book about the topic, I think we should end the first part of the introduction phase. We will tackle these topics and many more in the next part of <strong>Domain Driven Design like a Pro</strong>. You do have pretty good knowledge of DDD at this point, but there are still some topics that needs to be reflected on in order to fully grasp DDD and to be able to implement it into your own endeavours.</p><p>Stay tuned and comments are appreciated in the comment section below. I strive to make it easier for you to grasp the concepts, so feedback is important and highly appreciated 🎉</p><p>I would like to end on a note from an interview conducted by InfoQ where they asked Eric Evans about any pitfalls when trying to learn DDD. Evans responded:</p><blockquote>Don’t try to apply DDD to everything. Draw a context map and decide on where you will make a push for DDD and where you will not. And then don’t worry about it outside those boundaries. Experiment a lot and expect to make lots of mistakes. Modelling is a creative process. — Eric Evans</blockquote><p>Special thanks to the following resources for giving me the inspiration and ammunition to make this series:</p><h3>References:</h3><ol><li>Domain-Driven Design: Tackling Complexity in the Heart of Software <a href="https://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215">(Eric Evans)</a></li><li>Domain-Driven Design Reference: Definitions and Pattern Summaries <a href="https://www.amazon.com/Domain-Driven-Design-Reference-Definitions-Summaries/dp/1457501198/ref=pd_sbs_14_t_0/144-3635015-0442100?_encoding=UTF8&amp;pd_rd_i=1457501198&amp;pd_rd_r=8afef993-20e1-45f4-94b8-3006dac5eec7&amp;pd_rd_w=6O9xJ&amp;pd_rd_wg=4QADA&amp;pf_rd_p=5cfcfe89-300f-47d2-b1ad-a4e27203a02a&amp;pf_rd_r=MSD7JPHVP6JZRHDXW9DX&amp;psc=1&amp;refRID=MSD7JPHVP6JZRHDXW9DX">(Eric Evans)</a></li><li>Domain Driven Design Quickly <a href="https://www.infoq.com/minibooks/domain-driven-design-quickly/">(abel avram, floyd marinescu)</a></li><li>Patterns, Principles, and Practices of Domain-Driven Design (<a href="https://www.amazon.com/Patterns-Principles-Practices-Domain-Driven-Design/dp/1118714709">Scott Millett, Nick Tune</a>)</li><li>A Decade of DDD, CQRS and Event Sourcing <a href="https://tacta.io/a-decade-of-ddd-cqrs-and-event-sourcing/">(<em>Anes Hasičić)</em></a></li><li>Drafting a Functional Architecture Vision with Event Storming and DDD (<a href="https://philippe.bourgau.net/drafting-a-functional-architecture-vision-with-ddd-event-storming-part-1/">Philippe Bourgau</a>)</li><li>Domain storytelling (<a href="https://domainstorytelling.org/">Stefan Hofer</a>)</li><li>Introducing EventStorming (<a href="https://www.eventstorming.com/book/">Alberto Brandolini</a>)</li><li>Domain Driven Design Patterns in Python (<a href="https://www.youtube.com/watch?v=Ru2T4fu3bGQ&amp;t=2s">Robert Smallshire</a>)</li><li>Domain-Driven Design — What is it and how do you use it? (<a href="https://airbrake.io/blog/software-design/domain-driven-design">Andrew Powell-Morse</a>)</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9e78d081f10" width="1" height="1" alt=""><hr><p><a href="https://medium.com/raa-labs/part-1-domain-driven-design-like-a-pro-f9e78d081f10">Part 1: Domain Driven Design like a pro 🏅</a> was originally published in <a href="https://medium.com/raa-labs">Raa Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a pipeline in Azure DevOps to build and publish python packages/artifacts]]></title>
            <link>https://medium.com/raa-labs/creating-a-pipeline-in-azure-devops-to-build-and-publish-python-packages-artifacts-ea2f99410e6c?source=rss-cc4039c78bae------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea2f99410e6c</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[package-management]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <dc:creator><![CDATA[Anders Gill]]></dc:creator>
            <pubDate>Thu, 17 Oct 2019 12:46:50 GMT</pubDate>
            <atom:updated>2019-10-17T12:46:50.929Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>With </strong><a href="https://azure.microsoft.com/en-us/services/devops/"><strong>Azure DevOps</strong></a><strong> you can easily create sophisticated pipelines for your projects to ensure that the quality of your code and development process is coherent. In this guide, we will look at how we can develop a CI/CD pipeline to integrate package creation and sharing in a simple and scalable manner.</strong></p><p>Very often, Microsoft publishes fragmented steps on how to conduct specific tasks without providing important surrounding information for beginners to get things up and running. Assuming that the reader is an expert will often lead to articles that are hard to rely on as online resources for working examples. In this article, we will distill everything into digestible information that is easy to grasp, even for beginners.</p><h4><strong>During this article, we will dive into these topics:</strong></h4><ul><li>Preparing your code for a python project</li><li>Creating a python project locally</li><li>Difference between build and release pipelines</li><li>How to setup a build pipeline</li><li>Setting up unit tests in a build pipeline</li><li>Package creation in a build pipeline</li><li>Publishing artifacts in a build pipeline</li><li>Setting up a release pipeline to publish new artifacts with new verions</li><li>How to connect to feed and using your new package with python</li></ul><h3>Preparing your code for a python project</h3><p>If you want to upload your package to PyPi, I recommend this Medium article:</p><p><a href="https://medium.com/@joel.barmettler/how-to-upload-your-python-package-to-pypi-65edc5fe9c56">How to upload your python package to PyPi</a></p><p>A lot of the steps are the same, and we will go through how we can locally prepare our repository to have the necessary files in order to create the package in the next topic.</p><p>The first thing we need, is a repository. Raa Labs (the company I work for) uses <a href="https://github.com/">Github</a> and has a <a href="https://github.com/RaaLabs/TSIClient">Time Series Insight Client package available in Github.</a> We will use this example going forward. Once you have created an account on Github and uploaded your package code there, we can check if you have all the necessary files.</p><p>When you have your code in a repository, make sure to put your class files into a folder in your root directory with the same name as your class file. That folder will contain your classes while other necessary files will be listed in the root together with the class folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*wxs-mXkDP162QZu10zE5XA.png" /><figcaption>Screenshot of Class file within the folder within the Github repository</figcaption></figure><p>Example with needed files:</p><blockquote><em>TSIClient (Folder — name of my application)<br> → TSIClient.py (my class file)<br> → __init__.py<br>setup.py<br>setup.cfg<br>LICENSE.txt<br>README.md</em></blockquote><h3><strong>__init__.py</strong></h3><p>As you can see, there is a __init__.py file (two underscored on each side). This file should contain nothing other than an import statement for your class.</p><p><em>from packagename.Filename import Classname</em></p><p>Example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e19ef89ab9127e4fee2f153ea51663e7/href">https://medium.com/media/e19ef89ab9127e4fee2f153ea51663e7/href</a></iframe><p>The init file shows the access direction to your classes for the package interface.</p><h3><strong>Setup.py</strong></h3><p>Setup.py contains information about the package inself, and you are free to put in whatever information that suits your package. When creating new releases, this is the file you would use to update the package version. There are tons of examples which you can directly copy from. My setup.py looks like this for the TSIClient:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2df6f9181e62a4ccd37519c5e58c91cf/href">https://medium.com/media/2df6f9181e62a4ccd37519c5e58c91cf/href</a></iframe><p>Update the fields to suit your package.</p><p>In the install_requires field, you can fill out all the external python dependencies that your package requires to run successfully. In my case, I use pandas and requests as imports in my code, therefore I need to add them under install_requires within setup.py. Even though I import JSON as well in my code, I don’t need to list this as it comes built in with python.</p><p><strong>Setup.cfg</strong> is a simple file with some short metadata that links to your README.md file for description.</p><pre>[metadata]<br>description-file = README.md</pre><h3>LICENSE.txt</h3><p>Please insert your license type for the package. In most cases, you will be using the MIT license but I recommend you read up on what license suits your project. For the MIT type, use the skeleton below while changing out the appropriate text with the current year and your name:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41e8ee22be0efba924ecc8fbcbd2d586/href">https://medium.com/media/41e8ee22be0efba924ecc8fbcbd2d586/href</a></iframe><h3>README.md</h3><p>Last but not least, is the markdown readme file. This file should contain all your instructions for use in a markdown format and is referred to from the long_description variable in the setup.py file. The long_description is also the description that will be used in PyPi on the frontpage if you ever decide to upstream your package.</p><p>Adam pritchard has created a good <a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet">markdown cheatsheet</a> which you can use as your basis if you are new to markdown.</p><h3>Creating a python project locally</h3><p>At this point in time, you have successfully prepared your code to be packaged into a source distribution and distributed across whatever site you prefer. Congratulations! Now we will go ahead and create the actual source distributions that you can share.</p><p>Start with navigating from CMD into the folder where you have all your files.</p><pre>cd c:/path_to_your_folder</pre><p>From here, we will use python and sdist to create a source distribution from the setup.py file that we created earlier on.</p><pre>python setup.py sdist</pre><p>If this does not work, you can use Anaconda prompt or any other distribution to do the same. If you want to use CMD, just make sure that you have the appropriate python PATH set within your environment variables on windows.</p><p><strong>There should now be a new folder names dist which contains your new source distribution! 🎁</strong></p><p><strong>Uploading package to PyPi</strong></p><p>If you want to upload it to PyPi, simply write two more commands and follow the on screen instructions, and you will have your package uploaded to PyPi:</p><pre>pip install twine</pre><p>Twine is used for the upload process. Now that we have it installed, we can go ahead and upload the distribution with twine.</p><pre>twine upload dist/*</pre><p>Python does not allow for reusage of distributions however, therefore you should use the following command to avoid a “file already exists” error when updating your package.</p><pre>twine upload --skip—existing dist/*</pre><h3>Difference between build and release pipelines</h3><p>Now that we have created a package and know how to deal with it, we are going to dive into the world of DevOps. In DevOps, build and release are two commonly used names which we should understand before going forward. Also knowing how to differentiate those two words, is beneficial for us.</p><p>The user <strong>garchangle</strong> had a good <a href="https://www.reddit.com/r/devops/comments/c9a4n1/comment/esuwg8a?utm_source=share&amp;utm_medium=ios_app&amp;utm_name=iossmf">summarized explanation</a> on reddit about the difference between a build and a release pipeline:</p><blockquote>Build is taking your source and compiling/testing it. This should be done with some regularity and you aren’t necessarily expected to keep these builds. Its sort of a dev or team of devs checking to make sure the project they are building works like they expect. These can sometimes be called snapshot builds. You might deploy these builds to an environment, but only to test.</blockquote><blockquote>Releasing is the process of creating a permanent set of your code, compiled or noncompiled. This is when you have hit a milestone of some sort, time or feature wise. These releases are versioned and kept forever and once you start building more complex systems, you can refer to applications by this version for inter-dependencies.</blockquote><p>And if you are wondering how to seggregate Continuous Integration and Continuous Deployment in a build and release type of setting, the user by the name of <strong>myxored</strong> also added wisely to the <a href="https://www.reddit.com/r/devops/comments/c9a4n1/comment/esvxd0k?utm_source=share&amp;utm_medium=ios_app&amp;utm_name=iossmf">reddit thread</a>:</p><blockquote><strong>Build</strong>:</blockquote><blockquote>CI: The build-pipeline produces snapshot builds (and does e2e/it/unit tests ) of your code into artifacts which can be</blockquote><blockquote>CD: deployed on staging systems, test system or whatever you like</blockquote><blockquote><strong>Release</strong></blockquote><blockquote><strong>CI</strong>: usually promotes a already existing build artifact to a release. This usually adds a semantic version, puts that release into a nexus / artifactory of your kind to be consumed later</blockquote><blockquote><strong>CD</strong>: deploys a release on a set / all production systems</blockquote><blockquote>As you see, CI/CD are very different from Release/Build, CD can be described as “ship it to an external, permanent server” ( or sort alikes, hard to define ).</blockquote><h3>How to setup a build pipeline</h3><p>The first thing you need, is an account on Azure DevOps.</p><p>After you have set up your account, you need to create a new project within your organization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rQYx0cimoCj5xDESXaNnUg.jpeg" /></figure><p>After setting up your project, you can go to pipelines and build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*pG01BmFYv0MjEu4faKcRfA.jpeg" /></figure><p>Click on new build and click Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*ERbWMIMlL1jclvwonFPBcw.jpeg" /></figure><p>As you can see from the top row, there are a couple of steps we need to go through. One of them is configure, and we will look into how the YAML configuration looks like. Once you have selected your repository, you need to give some permissions for the Azure Pipelines app from the Github Marketplace. Click approve and install.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*iM_YBHX7tqfMNqh1APYgRw.jpeg" /></figure><h3>.YML file</h3><p>Now we need to configure our YAML file. This file works as the configuration file for our pipeline. The pipeline will read the YAML file from top to toe, so whatever code snippets we put in the YAML, the pipeline will run those consecutively.</p><p>This is how my YAML looks like. We will distill the file in a moment:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca5c8eaf91016a08aca5a62f987cf6f0/href">https://medium.com/media/ca5c8eaf91016a08aca5a62f987cf6f0/href</a></iframe><h3>Distilling and understanding the YAML file</h3><h4><strong>Trigger</strong></h4><p>Trigger sets which branch to trigger on from the repository. You can set this branch to be whatever you like. Mine is set to trigger the pipeline on the master branch.</p><h4>Pool</h4><p>The pool states which VM image and strategy the pipeline should run on. You can set this to run multiple python versions on specific images. Mine is set to run on ubuntu-latest with only python version 3.6.</p><h4>Steps</h4><p>Steps are the actual tasks that the pipeline should run. Here, you are free to set up as many steps as you like. The steps can involve any task from the tasks list, or you can write the yaml yourself if you are comfortable. In my yaml, I have the following steps:</p><ol><li>Use specific python version</li><li>Install dependencies</li><li>Install pytest and run pytest</li><li>Artifact creation</li><li>Copy artifacts</li><li>Publish artifact</li></ol><h4>1. Use specific python version</h4><pre>steps:<br>- task: UsePythonVersion@0  <br>      inputs:<br>        versionSpec: &#39;$(python.version)&#39;  <br>        displayName: &#39;Use Python $(python.version)&#39;</pre><p>The code above tells the pipeline to use the python version from the variable that was defined from the pool section. In my case, python 3.6.</p><h4>2. Install dependencies</h4><pre>- script: |    <br>    python -m pip install --upgrade pip<br>  displayName: &#39;Install dependencies&#39;</pre><p>The script above installs all the dependencies needed while making sure that pip is up to date</p><h4>3. Install pytest and run pytest</h4><pre>- script: |    <br>    pip install pytest pytest-azurepipelines    <br>    pytest  <br>  displayName: &#39;pytest&#39;</pre><p>The first command above installs the external pytest library. The second command simply runs the pytest module. We will go through how we can setup unit tests for our code in the next section. By adding the pytest command into your yaml, you will run the tests you have written.</p><h4>4. Artifact creation</h4><pre>- script: |    <br>    python setup.py sdist <br>  displayName: &#39;Artifact creation&#39;</pre><p>The code above is similar to what we wrote initially when creating a package from the source code. The artifact gets created in this stage.</p><h4>5. Copy artifacts</h4><pre>- task: CopyFiles@2  <br>  inputs:    <br>    targetFolder: $(Build.ArtifactStagingDirectory)</pre><p>The copy files task takes the artifact newly created and copies it to a target directory which is the build artifact staging directory variable. This is important to do so that we have control over where the artifact is currently stored so that we can publish the artifact form the same directory variable.</p><h4>6. Publish artifact</h4><pre>- task: PublishBuildArtifacts@1  <br>  inputs:    <br>    PathtoPublish: &#39;$(Build.ArtifactStagingDirectory)&#39;                  <br>    ArtifactName: &#39;dist&#39;    <br>    publishLocation: &#39;Container&#39;</pre><p>Last but not least, we take the dist artifact from the publish directory and publish the package named dist into Container. By doing this, we can pick it up from the release pipeline and proceed further.</p><p><strong>Congratulations! You have now created a fully functional build pipeline!</strong></p><p>In the end, this is how the job should look like after running it successfully:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-j0SZOn0tqba4eZQY5KXQ.jpeg" /></figure><p>You can even see that a source distribution by the name of “dist” was created.</p><p>By clicking on a step from the job, you can see further details from the log.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TAoJLw8SlQyyZOtemgePwQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HQz9aKDrK8NGhhH5utN_NA.jpeg" /></figure><p>Bu clicking on the “test”-tab, you can see deeper details about the tests that were run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aaqct7Z41kdSXhX2Q1mOBw.jpeg" /></figure><p>But how do we add tests to the code repository? We will answer this question in the next section.</p><h3>Setting up unit tests in a build pipeline</h3><p>Setting up tests with pytest is super simple. The only thing you need to do is to start your new file in which you want your tests to be with the word “test”.</p><p>Eg.</p><pre>test_collection.py</pre><p>Then commit this file into your repository.</p><p>In the build pipeline we are executing the installation of pytest and running pytest in step 3. With the integrated test discovery mechanism, pytest will automatically pick up the testfile when the word “test” stands as the filenames prefix. Make sure to put all of your test files in the root directory. If you put them in a folder, make sure to point the pipeline in the right direction.</p><p>Eg. of a simple assertion for squareroot of 25.</p><pre>import pytest<br>import math </pre><pre>def test_sqrt():   <br>    num = 25   <br>    assert math.sqrt(num) == 5</pre><p>When you have your test-file you are free to add the following into your existing yaml file which will be commited to your code repository And run by the pipeline:</p><pre>- script: |    <br>    pip install pytest pytest-azurepipelines    <br>    pytest  <br>  displayName: &#39;pytest&#39;</pre><h3>Setting up a release pipeline to publish new artifacts with new package versions</h3><p>In order to create your first release pipeline, go to Pipelines and Release, then click on “new release”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*VHIFNzkN7e76-QbY6ONf3A.jpeg" /></figure><p>Start by giving your release pipeline a proper name. The pipeline will contain zero stages initially and cannot be run. We will fix this in a moment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9lRerCAXeJhNvfMgF5uzHA.jpeg" /></figure><p>Go into the options-tab and revise how you want the version naming convention to be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*9uPJkNS3fVi3OMmhvHcJ9Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HpfBmxRg5dnBpZJmO5ZFiQ.jpeg" /></figure><p>The following code:</p><pre>Release-$(rev:r)</pre><p>will yield sequential release names like:</p><p>eg.</p><pre>Release-19</pre><p>You can edit the naming schemes if wanted. Here is a <a href="https://docs.microsoft.com/nb-no/azure/devops/pipelines/release/index?view=azure-devops">list from Microsoft </a>with possible masks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yw-s5i50PwSZQM6Z85beEA.jpeg" /></figure><p>Click on the blank artifact section to add a connection from the build artifact to the release pipeline. Pick the Build source and pay attention to the artifact name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3n6yUXgVDWeTuRf55mg0Dg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*EZyv3usm0kEO-warfrzpqg.jpeg" /></figure><p>You can at this point decide whether the release pipeline should be triggered each and every time the build pipeline has been run, or you can choose to schedule it for specific timings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yiGEZZjWL2pkhIiUhZbu6g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0sYrbyJusgeOdAA5ibL00g.jpeg" /></figure><p>Now we are ready to create a new stage. Click on “new stage” and give your stage an appropriate name. I named mine “Publish new artifact”. You can create multiple stages. One example is to have a production stage, another one for development and the last for staging. Within your stages, you can have multiple tasks, just like in the build pipeline. In my stage, I have three tasks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*uwZjb-qvpx6FGd1f6SZjcg.jpeg" /></figure><p>Before we dive into the tasks of publishing the package, we need to create a “feed”. Go to the “artifacts” section and click on “add new feed”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_oPRTPqUaIdH3dhBK0SRg.jpeg" /></figure><p>Give your feed a name and choose the access control. Go back to the steps section in the release pipeline and click on tasks.</p><p>Click on “Add a task to Agent job”.</p><p>Search for “<strong>Python twine upload authentication</strong>” and “<strong>Command Line</strong>”. Make sure to add the tasks to the list to make it match to what I have done below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kkg3NweqLpp8laTDi0wDsg.jpeg" /></figure><p>Select the newly created feed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vhpyP-_9HM2FSTLMw2N8LQ.jpeg" /></figure><p>In the second command line task, write a short script to install twine through python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BAZfQaerK1q-6Qho4qd2lA.jpeg" /></figure><p>The last command line script is a bit tricky. This is the actual publication script that will take the package from a specific path the build source distribution is located at, and upload it to the particular feed with the PYPIRC_PATH environment variable that contains the twine authentication from the first task you created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*06CEA4k8w7Oc4UId7OP1UA.jpeg" /></figure><pre>twine upload -r {NAME_OF_FEED} --config-file $(PYPIRC_PATH) d:\a\r1\a\_{NAME_OF_ORGANIZATION}.{PACKAGE_NAME}\dist\dist\*</pre><p><strong>You are now ready to create a release! 🎉</strong></p><p>Based on how you triggered your release pipeline, either make a commit to the code repository on Github or deploy the release manually.</p><p>By the end of the release, this is how it should look like if all went well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r-mZAQ3jay8dLUQWTZIcuQ.jpeg" /></figure><p>You can go to the artifacts section and find your newly published package. 📦</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JGroE5U9P1OX-rup5t04Xw.jpeg" /></figure><p>You can click on the package and read more about how to use it if you wrote a README.md file. Click on the “connect to feed” button if you want to connect your environment to the current feed and install the package.</p><p>NB! Only after you have connected to the feed, will you be able to pip install your package. Unless the package is upstreamed to a public index like PyPi, you need to connect your environment to the feed before you can pip install.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zqdkfWU9uCZEvHUfNxaHxw.jpeg" /></figure><h3>How to connect to feed and using your new package with python and pip.ini</h3><p>After clicking on “connect to feed”, a popup appears that tells you how to connect to the feed. My personal understanding of this was that it felt a bit lacking in information. I had never used a pip.ini file myself, so after tons of researching I finally found the best way of creating a pip.ini file to add the Python generated credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T99dUWPqfKxMf4yV8ERB7Q.jpeg" /></figure><p><strong>Installation guide for anaconda virtual environment.</strong></p><ol><li>Open notepad or other text editor program.</li><li>From Azure DevOps, click on <strong>Generate Python credentials</strong> for a pip.ini file</li><li>Copy the python credentials into the text editor</li><li>Save as pip.ini (no textfile)</li><li>Go to C:\Users\User.Name\.conda\envs\Your-env (Example: C:\Users \Anders.Gill\.conda\envs\DevOpsEnv)</li><li>Save the pip file in the aboveforementioned path</li><li>Go to command terminal for your virtual environment</li><li>pip install NAME_OF_PACKAGE==current-version (1.0.2 for example)</li><li>Installation successful</li></ol><p><strong>Congratulations, you have now successfully created a fully functional CI/CD pipeline for your project! Hope you enjoyed this guide and will recommend it forward. 🎉</strong></p><p>Feel free to ask any questions in the comments below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea2f99410e6c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/raa-labs/creating-a-pipeline-in-azure-devops-to-build-and-publish-python-packages-artifacts-ea2f99410e6c">Creating a pipeline in Azure DevOps to build and publish python packages/artifacts</a> was originally published in <a href="https://medium.com/raa-labs">Raa Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>