<?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 Damian Perera on Medium]]></title>
        <description><![CDATA[Stories by Damian Perera on Medium]]></description>
        <link>https://medium.com/@damianperera?source=rss-7f59c8bbd6d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eMteYodwzNRpibcESyffAA.jpeg</url>
            <title>Stories by Damian Perera on Medium</title>
            <link>https://medium.com/@damianperera?source=rss-7f59c8bbd6d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 19:03:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@damianperera/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[Finding the Maximum Accessible Area on a 2D Grid]]></title>
            <link>https://damianperera.medium.com/finding-the-maximum-accessible-area-on-a-2d-grid-198e1124d306?source=rss-7f59c8bbd6d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/198e1124d306</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming-challenge]]></category>
            <category><![CDATA[graph-theory]]></category>
            <dc:creator><![CDATA[Damian Perera]]></dc:creator>
            <pubDate>Sat, 05 Jun 2021 09:19:34 GMT</pubDate>
            <atom:updated>2021-06-05T09:19:34.455Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using a Programmatic Representation of Graphs</h4><p>I came across this question on <a href="https://stackoverflow.com/questions/64218531/dynamic-programming-problem-maximum-accessible-area-on-a-2d-grid">StackOverflow</a> listed under Dynamic Programming, but there didn’t seem to be an accepted solution with an explanation — so I figured I’d give it a shot and document the solution along-with my thought process.</p><p>Enjoy!</p><h3>The Problem</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HyOrkriX9x3kXRdAyxyvGw.jpeg" /></figure><p>There is a character who can move around on a two-dimensional <em>(x,y)</em> coordinate grid. The character is placed at point <em>(0,0)</em>.</p><p>From <em>(x, y)</em> the character can move to <em>(x+1, y)</em>, <em>(x-1, y)</em>, <em>(x, y+1)</em>, and <em>(x, y-1)</em>.</p><p>Some points are dangerous and contain land mines. To know which points are safe, we check whether the sum of the digits of <em>abs(x)</em> plus the sum of the digits of <em>abs(y)</em> are less than or equal to 23.</p><p>For example, the point <em>(64, -59)</em> is not safe because 6 + 4 + 5 + 9 = 24, which is greater than 23. The point <em>(105, -17)</em> is safe because 1 + 0 + 5 + 1 + 7 = 14, which is less than 23.</p><p>How large is the area that the character can access?</p><h3>The Solution</h3><p>You need to output the count of points in the graph that the character can move to safely — there has to be a linear progression in the movement, you cannot simply count the number of coordinates in the graph where the sum of its values is less than 24.</p><p>Before we code this solution, it’s important to understand the coordinate system in the real world vs its programmatic representation.</p><h4>The Coordinate System</h4><p>To start off you first need to remember that an Array cannot have negative indices, therefore in order to create a graph that has both negative and positive coordinates you need to have an array twice as long as the 0..n length of an axis. For example, if you need the <em>x</em>-axis to range from -100..100 you will need an array of length AXIS_LENGTH * 2 to accommodate these coordinates where AXIS_LENGTH = 100.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bnot_PJV2sDHLgpfHAEWTw.png" /><figcaption>The Programmatic Representation of a Graph</figcaption></figure><p>Since a graph is technically a data structure represented using rows and columns, we can easily represent it using a 2D array.</p><blockquote><strong>Important Note:</strong> When representing a graph using a 2D array the <em>y</em>-axis will become inverted (i.e. the positives of the values of the y-axis will be below the origin point) because in the real-world the y-axis is represented bottom-up whereas in an array we cannot maintain inverted indices.</blockquote><p>We consider the origin point of a real-world graph to be at <em>(0,0)</em> — however, if we attempt to use these same coordinates to map the origin point in our 2D array, you’ll see that graph[0][0] will map to the upper-left most element, and not the element at the centre of the grid. The actual origin of the graph would be the coordinate at the centre of the grid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*Dco1L4f-InltLPYrFfDf0w.png" /><figcaption>Visualization of the Coordinate System</figcaption></figure><p>In order to get the middle element of both rows and columns, we would need to divide the actual length of an axis by 2, which would mean that the origin point would be at (row.length/2, col.length/2) — however, we know that both the rows and columns were set to AXIS_LENGTH * 2, therefore, the origin should be at (AXIS_LENGTH, AXIS_LENGTH) which would translate to <em>(5,5)</em>.</p><p>We can use this same logic to translate a coordinate on a real-world graph into our grid by adding the AXIS_LENGTH to its <em>x</em> and <em>y</em> values.</p><p><em>e.x.</em> If you were to fetch the location of coordinate <em>(3,4)</em> in a graph where AXIS_LENGTH = 5 you would need to add the AXIS_LENGTH to each coordinate point to identify this position on our 2D grid, therefore you would find your actual coordinate at (3 + AXIS_LENGTH, 4 + AXIS_LENGTH) which would be <em>(8,9)</em>. As you can see below, the coordinates of point <em>β</em> read <em>(3,4)</em> when you consider its location along the <em>x</em> and <em>y</em> axes, but its actual position in our 2D array is at graph[8][9].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*-XPjSrS2CTJzMQZ_HhE96w.png" /><figcaption>Coordinate Mapping — Graph to 2D Array</figcaption></figure><h4>Pseudocode</h4><p>Now that we’ve established the coordinate system in our grid, we can explore the practical aspects of our solution.</p><p>1 - First, you will need to create your data structures.</p><ul><li>A 2D Boolean grid is the primary data structure and will be used to maintain a record of where the character visited — so as to avoid duplicates.</li><li>An ArrayDeque is used as a Stack (I know its a double-ended queue, but for the sake of simplicity I’m going to call it a Stack) to maintain a record of the last visited locations of the character. This will be the main driver of the iterative loop.</li><li>An ArrayList is used to maintain the list of possible directions that a character can move in at any given coordinate.</li></ul><p>2 - Before we start the iterative loop, we need to establish the origin point of the character. For this purpose, we will push the point of origin to the Stack and set the origin point in the grid to true.</p><p>3 - We can now start iterating the Stack to fetch the last known positions of the character in order to move it in the directions specified by the ArrayList.</p><p>4 - As and when you find a new safe coordinate to move to, increment the counter, mark it as visited and push this location to the Stack so that we can continue the iteration.</p><p>Once the character has moved to every possible coordinate in our grid there will no longer be any last known locations in the Stack (since we pop them before we compute new positions), which brings us to the end of our iterative loop.</p><p>Your area variable will now contain a count of all the safe locations in the grid.</p><p>A Java-based solution that I coded can be found below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a71b9b02124d9720f28cbce16680a54/href">https://medium.com/media/8a71b9b02124d9720f28cbce16680a54/href</a></iframe><h4>Final Thoughts</h4><p>For some reason as long as the threshold value is constant and the length of the axes is above 1,000 the final count is always <strong>592,597 </strong>— so there might be a mathematical concept to help solve this with an <em>O(n)</em> complexity without over-engineering it as I did.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=198e1124d306" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Behavior Driven Testing in Enterprise Applications]]></title>
            <link>https://faun.pub/behavior-driven-testing-in-enterprise-applications-cec9b2d7a9ff?source=rss-7f59c8bbd6d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/cec9b2d7a9ff</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[testing-framework]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Damian Perera]]></dc:creator>
            <pubDate>Tue, 19 May 2020 08:43:18 GMT</pubDate>
            <atom:updated>2020-05-21T08:39:27.813Z</atom:updated>
            <content:encoded><![CDATA[<h4>A look into reducing bug leakages in microservices shared across multiple development teams</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WNNHXeItIfDtba5LIMuUYA.jpeg" /></figure><p>I work in a software organization where change is frequent, to say the least. As a developer and part of a larger team building an e-commerce platform, we’ve more or less adapted to frequent changes in project management, development methodologies, testing ideologies and of course now (given the current global pandemic), remote collaboration. This behavior-driven test strategy was developed within our team as a way to reduce bug leakages in mission-critical systems as our organization grew to include off-shore development teams (with product owners representing different customer interests)—and in order to ensure that the quality of the systems would not be affected by evolving engineering philosophies over the years.</p><h3>Background</h3><p>When working with an enterprise application powered by microservices you can end up with a lot of sub-systems designed to handle different parts of a user&#39;s experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*NwmBZj6QB8Vg_5XAU1Vczw.png" /><figcaption>A typical e-commerce ecosystem</figcaption></figure><p>In an e-commerce setting these microservices might be scoped to manage users, orders, payment processing, product recommendations, product search, etc. leading to a lot of moving parts under the hood. Depending on the design of the system, each microservice might consume a bunch of others based on a predefined flow to complete a user action.</p><p>An example would be a user wanting to know the delivery ETA of an order while in the order details page. In order to generate an ETA for the delivery (as per the diagram above), the delivery microservice would need to fetch the order stored with the order management service, cross-check its location with the warehouse and logistics services, fetch driver information and estimate a delivery time depending on a GPS marker. That’s four different sub-systems working in unison to populate a label on the user’s screen with the delivery information of an order.</p><h3>The Problem</h3><p>As and when your product grows, so will the requirements of your target users and in extension the demands of your product owner. This is when our software organization started to expand and grow, breaking off into smaller specialized business units (or verticals) focused on developing a part of a user experience like tracking the delivery of an order rather than taking tickets from a common project backlog in a round-robin manner.</p><p>When you have teams working on different aspects of a customer’s experience you tend to get new features that require changes across many sub-systems — and having many developers building multiple features across the entire stack at the same time is a really big risk if you don’t have a proper test suite.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*JXyVi6t4vdSnKDzZ8xbDsA.png" /><figcaption>‘When should I mock?’ via <a href="https://stackoverflow.com/a/38256/4856492">StackOverflow</a></figcaption></figure><p>In a unit test suite, the problem with mocking every dependency is that if you change a method’s functionality, and other methods in its call hierarchy have already mocked it, you won’t know if any functionality different to your own has been broken. This becomes a significant problem for developers (both new and old alike) since it’s difficult to comprehend the entire affected scope of a changeset.</p><p>You might end up breaking an already working flow belonging to a team that handles order placement when implementing a feature related to order tracking in the order management service.</p><h4>But isn’t that why we have Integration Tests?</h4><p>True. But once you’ve included tests for every edge-case, bug, and race-condition in addition to the existing cases in your integration test suite your test pyramid is going to look a lot like the one we had.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*2gS_XnNhOHgXo3rvCyoOVQ.png" /></figure><p>Although we had more than 80% coverage in all our unit test suites the reason it looks more like an ice-cream cone than a pyramid was because we added on so many integration and E2E test cases that towards the end some integration suites would take over 60 minutes to complete — that’s 1 hour wasted by a developer waiting to know if their code change broke another feature in the service — and with the suite running on a CI server it’s still going to be difficult to understand the entire scope of the broken tests and narrow down the impacted area to debug the faulty logic.</p><h3>The Solution</h3><p>We came up with an integration test suite that could be used to test entire API flows within a microservice while co-existing with unit tests, and which would be executed automatically along with the unit test suite. A test would be executed from the service method that the REST controller uses while mocking only the external database and API calls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*Bg1xhR-7UICGTyMV5EpgwA.png" /><figcaption>Real Flows vs Behaviour Driven Test Flows</figcaption></figure><p>As shown above, we only mock anything outside the control of the service i.e. the database (using <a href="https://www.testcontainers.org/">TestContainers</a>) and external API calls (using <a href="http://wiremock.org/">WireMock</a>). Unlike normal integration tests, this allows us to assert not only the response object sent from the service but also the state of the database as well as the API requests that were sent to the stubs. We can also configure the database and stubs to return different results to the service in order to recreate successful, buggy, and edgy flows in order to assert the correct behavior during those scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*il7Dafus9K0t6XKzE15lmg.png" /><figcaption>BDT Assertions</figcaption></figure><p>Since this strategy allows you to control and assert all the entry and exit points of your service, you have the ability to write test cases to verify the exact behaviour of the relevant API endpoint.</p><h4>Naming Conventions</h4><p>This is where BDT gets its name. Remember that you are testing a complete flow in the viewpoint of a downstream service. A test case for the previous example which returns the delivery ETA of an order (GET /order/:orderId/location) where you also need to simulate the failure of an upstream service would look like the one shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6rkDrPGs-ZBH8mY5t8maUA.png" /></figure><p>Here the name of the test case should represent the expectation of the service that would be consuming that method via an API invocation as per the contract. We also try to make sure that the name clearly identifies the test scope so that a developer would be able to look at a test case and immediately know what is expected.</p><h3>The Results</h3><p>Since these new tests execute along with the existing unit tests, and since the database and external APIs are mocked, we’ve seen around 1500 test cases completing within a couple of minutes — that’s around 95% faster than what our previous integration test suite running on a CI server would have taken while more or less covering the same test cases.</p><p>While we didn’t completely flip around our test ice-cream cone, we were able to grow our unit test layer to include many test cases that would otherwise have required real database and third-party service calls, leaving our integration and E2E test suites to cover only the most vital flows (the happy and bad paths).</p><p>Now if a developer working from anywhere in the world was building a feature or fixing a bug and inadvertently broke any established API behaviours, they would see the exact impact of the change in their local environment itself and fix it without waiting for a quality gate failure or a bug reported in a cloud environment — which significantly reduces the number of bug leakages as well as the time to completely release a ticket.</p><p><strong>Disclaimer:</strong> The testing strategy described here is not meant to be a replacement for unit tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and </strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷 <strong>and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook</strong></a><strong> and </strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin</strong></a><strong> Groups </strong>💬<strong>.</strong></p><p><strong>To join our community Slack team chat </strong>🗣️ <strong>read our weekly Faun topics </strong>🗞️,<strong> and connect with the community </strong>📣<strong> click here⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_cT0_laE4iPcqW1qrbstAg.gif" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cec9b2d7a9ff" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/behavior-driven-testing-in-enterprise-applications-cec9b2d7a9ff">Behavior Driven Testing in Enterprise Applications</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Mixed Reality Development on the Microsoft HoloLens]]></title>
            <link>https://damianperera.medium.com/understanding-mixed-reality-development-on-the-microsoft-hololens-5a3458fd487a?source=rss-7f59c8bbd6d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a3458fd487a</guid>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[mixed-reality]]></category>
            <category><![CDATA[hololens]]></category>
            <dc:creator><![CDATA[Damian Perera]]></dc:creator>
            <pubDate>Sun, 02 Feb 2020 03:20:53 GMT</pubDate>
            <atom:updated>2020-11-06T14:50:07.944Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ir4XlZOFNjjDEeak06ejEQ.jpeg" /></figure><p>This article was originally published on my personal blog in November 2016 and is recommended for developers looking to begin development for the HoloLens 1 Developer Edition — in no way does this cover the entire spectrum of game physics, programming paradigms, and concepts that a developer needs to know when building advanced applications for the HoloLens or any other Mixed Reality device.</p><p>In order to understand the concept of Mixed Reality, one must first be familiar with the terms of Virtual Reality and Augmented Reality, for Mixed Reality is a culmination of both the Virtual and Augmented scopes.</p><ul><li><strong>Virtual Reality</strong> refers to the simulation of a user’s physical presence in a virtual environment.</li><li><strong>Augmented Reality</strong> refers to the view of a physical environment where some or all of its elements are augmented by computer-generated input.</li></ul><p>Mixed Reality (also referred to as Hybrid Reality) refers to the merging of both Virtual and Augmented Reality where the physical environment and the virtual environment co-exist based on several paradigms.</p><p>In Mixed Reality, one scenario can be where computer-generated elements are augmented into the real world, whereas another scenario can be where the real world is replaced by a virtual one (e.g. <a href="https://www.microsoft.com/microsoft-hololens/en-us/apps/HoloTour">HoloTour</a><em>).</em> In this post, I’ll review and shed some light on the functioning of the Microsoft HoloLens headset, the first Mixed Reality device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m2pdrM2gLQyvz_PlvJegyA.jpeg" /><figcaption>RoboRaid — A look into the Augmented Reality capabilities of the HoloLens</figcaption></figure><h3>Microsoft HoloLens</h3><p>The HoloLens is a Mixed Reality device powered by a modified version of the Windows 10 IoT Core. It’s forte and the power that drives its complex system is the Holographic Processing Unit (HPU) developed to render graphics based on DirectX 11.</p><p>The advantage of having a Holographic Processor based on DirectX 11 that supports the Universal Windows Platform (UWP) is that developers can build holographic applications using existing suites and frameworks such as <a href="https://unity3d.com/partners/microsoft/hololens">Unity </a>and <a href="http://windowscomments.com/?p=2087">SharpDX</a>. Seeing as Unity is already a fully-fledged game engine, and since it supports Windows Holographic out of the box, we will look into the development of applications based on Unity 5.4.x.</p><p>Anyone who develops for the HoloLens on top of Unity needs to be familiar with it’s Game Physics and Input Paradigms.</p><h3>Game Physics</h3><p>The <a href="https://docs.unity3d.com/550/Documentation/ScriptReference/VR.WSA.Input.GestureRecognizer.html">HoloLens API</a> <em>(</em>UnityEngine.VR.WSA<em>)</em> provides spatial mapping and plane detection, whereby we create a mesh collider called the SpatialMappingCollider<em> </em>(SMC) for each surface plane. The SMC includes renderer components and a Spatial Mesh component (used to occlude virtual GameObjects with the real environment). All interactions and animations are conducted within this collider where GameObjects and Rigid Body Physics use the collider as the default horizontal and vertical plane. Every GameObject that uses spatial mapping for placing as well as animations will use the SMC to identify floors and walls.</p><p>In order for the game engine to correctly position and apply game physics to GameObjects, they should contain a box collider in order to supplement the SMC. The behaviour, collision detection and interaction between the SMC and the different GameObject colliders is the basis for Game Physics in the augmented environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*cU1ol8LPFbc0hoJ2Osis2Q.gif" /><figcaption>How the HoloLens sees the real environment</figcaption></figure><h3>Input Paradigms</h3><p>Input for the HoloLens manifests in three main forms known as GGV.</p><ul><li><strong>G</strong>aze — Simulates mouse pointing in the environment</li><li><strong>G</strong>esture — Simulates selection, drag and drop, bloom etc. in the virtual environment</li><li><strong>V</strong>oice — Allows the user to issue voice commands for predefined interactions or inputs</li></ul><p>In addition to the GGV Input Paradigm, the HoloLens uses Spatial Sound for immersive sound output in the virtual environment. Using Spatial Sound, a developer can simulate the origin of an audio source — the closer a user is to the sound source, the clearer and louder it can be heard, and vice versa.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bgTwDdpCvrqfby_RmQHLBA.jpeg" /><figcaption>Gaze, Gesture and Voice</figcaption></figure><p>Since every input form in the HoloLens is done via GGV, a developer must be thorough with the usage of all three input sources, in order to use them in conjunction with each other.</p><p>An important point of note is that contrary to popular belief, the Gaze input is not provided by the operating system — it is instead a user-programmed input source, using the Raycast Hit from the main camera position (transform.position) and it’s a direction (transform.forward)<em>.</em> Hence, the cursor design and behaviour is completely user-programmable.</p><p>As a beginner to Unity and the MR field, it took me quite a while to figure out the basics that drive every MR application built on top of UWP and the Unity Game Engine. I hope this post helps anyone looking to begin development on the Microsoft HoloLens. I would recommend checking out the <a href="https://github.com/Microsoft/HoloToolkit-Unity">Microsoft HoloToolkit for Unity</a> for a helping hand in development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a3458fd487a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Docker?]]></title>
            <link>https://faun.pub/why-docker-8a388c671a04?source=rss-7f59c8bbd6d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a388c671a04</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <dc:creator><![CDATA[Damian Perera]]></dc:creator>
            <pubDate>Mon, 27 Jan 2020 16:55:51 GMT</pubDate>
            <atom:updated>2020-05-17T02:34:44.422Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn how Docker is transforming the way we code</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gksapx9sxF5wN44J72w1vQ.png" /><figcaption>Image by itl.cat via Google Images</figcaption></figure><p>Ever since Docker went live in early 2013 it’s had a love-hate relationship with programmers and sysadmins. While some ‘experienced’ developers that I’ve talked to have a strong dislike for containerization in general (more on that later), there’s a reason why a lot of major companies including eBay, Twitter, Spotify and Lyft have reportedly adopted Docker in their production environments.</p><h3>So what exactly does Docker do?</h3><p>Ever worked with VMware, VirtualBox, Parallels or any other virtualization software? Well, Docker’s pretty much the same (albeit without a fancy GUI) where it creates a virtual machine with an operating system of your choice bundled with only your web application and its dependencies.</p><h3>But aren’t virtual machines slow?</h3><p>Virtualization is what drives the cloud computing revolution, and I like to call Docker the last step of virtualization which actually executes the business logic that you’ve developed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/1*m6lTlAt-ORkgyWbsj9bZiA.png" /><figcaption>A typical cloud server setup</figcaption></figure><p>But, your right — typical virtual machines are slow and what Docker does cannot be entirely categorized under virtualization. Instead, Docker provides an abstraction on top of the kernel’s support for different process namespaces, device namespaces etc. by using <a href="https://github.com/opencontainers/runc">runc</a> (maintained by the <a href="https://www.opencontainers.org/">Open Containers Initiative</a>) which allows it to share a lot of the host system’s resources. Since there isn’t an additional virtualization layer between the Docker container and the host machine’s kernel a container manages to provide nearly identical performance to your host.</p><p>A fully virtualized system gets its own set of resources allocated to it and does minimal sharing (if any) which results in more isolation, but it’s heavier (requiring more resources) — however, with Docker, you get less isolation but the containers are pretty lightweight (requiring fewer resources).</p><p>If you need to run a system where you absolutely require full isolation with guaranteed resources (e.g. a gaming server) then a virtual machine based on KVM or OpenVZ is probably the way to go. But, if you just want to isolate separate processes from each other and run a bunch of them on a reasonably sized host without breaking the bank, then Docker is for you.</p><p>If you want to learn more about the performance aspects of running a containerized system here’s a great research paper from IBM: <a href="http://domino.research.ibm.com/library/cyberdig.nsf/papers/0929052195DD819C85257D2300681E7B/$File/rc25482.pdf"><em>An Updated Performance Comparison of Virtual Machines and Linux Containers</em></a> (2014, Felter et. al) that does a sound comparison of virtual machines and containers.</p><h3>Can’t I simply upload my application straight on to a bunch of cloud servers?</h3><p>Well you can, if you don’t care about stuff like infrastructure, environment consistency, scalability or availability.</p><p>Imagine for a moment the following scenario: you manage a dozen Java services and deploy them on separate servers running Ubuntu with Java 8 for your Dev, QA, Staging and Production environments. Even if you haven’t made your applications highly available that’s a minimum of 48 servers that you need to manage (12 services x 4 environments).</p><p>Now imagine your team spearheads an organization change policy requiring you to upgrade your runtimes to Java 11. That’s 48 servers that you need to log in to and manually update. Even using tools like Chef or Puppet, that’s a lot of work.</p><h4>Here’s a simpler solution</h4><p>Docker lets you create a snapshot of the operating system that you need and install only the required dependencies on it. One side of this that I love is that you can manage all the ‘bloatware’ or lack thereof. You could use a minimal installation of Linux (I recommend <a href="https://alpinelinux.org/">Alpine Linux</a>, although for the purpose of this article I’ll continue with Ubuntu) and only install Java 8 on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*vvF_ulOtCxlIXtv0WVnHtg.png" /></figure><p>When the time comes to update, simply edit your Java image’s Dockerfile to use Java 11, build and push to a container repository (like Docker Hub or Amazon ECR), after which all you need to do is change your application containers base-image tag to reference the new snapshot and re-deploy them.</p><p>Below is a sample Docker container built on top of the Ubuntu 18.04 minimal operating system.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de32e9fa158c747925e8643045c48375/href">https://medium.com/media/de32e9fa158c747925e8643045c48375/href</a></iframe><p>I would build and push this image to the Docker Hub account damian using the tag oracle-jdk-ubuntu-18.04:1.8.0_191 and then use it to build another container for my services to run on:</p><pre># Instructs Docker to build this container on top of this snapshot<br>FROM damian/oracle-jdk-ubuntu-18.04:1.8.0_191</pre><pre># Copys the application JAR to the container<br>COPY build/hello-world.jar hello-world.jar</pre><pre># Executes this command when the container starts<br>CMD java -jar hello-world.jar</pre><p>Now if I needed to update my services to Java 11, all I need to do is publish a new version of my Java snapshot with a compatible JRE installed, and update the tag in the FROM declaration in the service container, instructing the container to use the new base image. Voila, with your next deployment you’ll have all your services up-to-date with the latest updates from Ubuntu and Java.</p><h3>But how would this help me during development?</h3><p>Good question.</p><p>I recently started using Docker in unit tests. Imagine you’ve got thousands of test cases (and if you do, believe me, I feel your pain) which connect to a database where each test class needs a fresh copy of the database and whose individual test cases will perform CRUD operations on the data. Normally one would reset the database after each test using something like <a href="https://flywaydb.org/">Flyway</a> by Redgate, but this means that your tests would have to run sequentially and would take a lot of time (I’ve seen unit test suites that take as long as 20 minutes to complete because of this).</p><p>With Docker, you could easily create an image of your database (I recommend <a href="https://www.testcontainers.org/">TestContainers</a>), run a database instance per test class inside a container, and then run your entire test suite parallelly. Since all the test classes are running in parallel and are linked to separate databases, they could all run on the same host at the same time and finish in a flash (assuming your CPU can handle it).</p><p>Another place I find myself using Docker is when coding in Golang (whose configurations and dependency management I find to be messy )— instead of directly installing Go on my development machine I follow a method similar to <a href="https://levelup.gitconnected.com/how-to-live-reload-code-for-golang-and-docker-without-third-parties-ee90721ef641">Konstantin Darutkin</a>’s by maintaining a Dockerfile with my Go installation + dependencies configured to live-reload my project when I make a change to a source file.</p><p>This way since I’ve got my project and Dockerfile version-controlled, and if I ever need to change my development machine or reformat it, all I need to do is simply reinstall Docker to continue from where I left off.</p><h3>To sum up…</h3><p>If you are a startup undecided on what’s going to power your new tech stack, or an established service provider thinking of containerizing your Prod and NonProd environments but fear sailing on ‘untested’ waters (smirk), consider for a moment the following.</p><h4>Consistency</h4><p>You might have the best developers in the entire industry, but with all the different operating systems out in the wild everyone prefers their own setup. If you’ve got your local environment properly configured with Docker, all a new developer need do is install it, spawn a container with your application and kick-off.</p><h4>Debugging</h4><p>You can easily isolate and eliminate issues with the environment across your team without needing to know their machine setup. A good example of this is when we once had to fix some time synchronization issues on our servers by migrating from <a href="https://en.wikipedia.org/wiki/Ntpd">ntpd</a> to Chrony — and all we did was update our base image, with our developers being none the wiser.</p><h4>Automation</h4><p>Most CI/CD tools including Jenkins, CircleCI, TravisCI etc. are now fully integrated with Docker, which makes propagating your changes from environment to environment a breeze.</p><h4>Cloud Support</h4><p>Containers need to be monitored and controlled or else you will have no idea what’s running on your servers and DataDog, a cloud-monitoring company had this to say on Docker:</p><blockquote>Containers’ short lifetimes and increased density have significant implications for infrastructure monitoring. They represent an order-of-magnitude increase in the number of things that need to be individually monitored.</blockquote><p>The solution to this monstrous endeavour is available in self-managed cloud orchestration tools such as <a href="https://docs.docker.com/engine/swarm/">Docker Swarm</a> and <a href="https://kubernetes.io/">Kubernetes</a> as well as vendor-managed tools such as AWS’s <a href="https://aws.amazon.com/ecs/">Elastic Container Service</a> and the <a href="https://cloud.google.com/kubernetes-engine/">Google Kubernetes Engine</a> which monitor and manage container clustering and scheduling.</p><p>With the widespread use of Docker and its tight integration with Cloud Service Providers like AWS and Google Cloud, its quickly becoming a no-brainer to dockerize your new or existing application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and </strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷 <strong>and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook</strong></a><strong> and </strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin</strong></a><strong> Groups </strong>💬<strong>.</strong></p><p><strong>To join our community Slack team chat </strong>🗣️ <strong>read our weekly Faun topics </strong>🗞️,<strong> and connect with the community </strong>📣<strong> click here⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6P3WpLjGv5v1ucm5dgkucg.png" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a388c671a04" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/why-docker-8a388c671a04">Why Docker?</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reduce your cloud infrastructure costs by using Scheduled Tasks on AWS]]></title>
            <link>https://faun.pub/scheduled-tasks-on-aws-ecs-520172a83a9c?source=rss-7f59c8bbd6d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/520172a83a9c</guid>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <category><![CDATA[scheduled-tasks]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Damian Perera]]></dc:creator>
            <pubDate>Wed, 22 Jan 2020 16:18:21 GMT</pubDate>
            <atom:updated>2020-02-17T10:08:46.018Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn how and why you need to switch to ECS Scheduled Tasks when running periodically scheduled services</h4><figure><img alt="Featured Image" src="https://cdn-images-1.medium.com/max/1024/1*8elCLa64Ibbdoe-5PUt_pA.jpeg" /></figure><p>ECS allows you to deploy and run containers on a fully-managed orchestration service (similar to Kubernetes). While the most common use case of ECS (as far as I know) is to continuously run services on containers, there could be some architectural designs that require some services to only run periodically.</p><p>One way to achieve this would be to add a cron job to the Dockerfile of the container in order to start the service periodically (while running the cron daemon in the foreground). The drawback of this would be that you would have a container with a service that needs to run only <em>x</em> minutes per day but would be continuously reserving (and therefore being billed for) the resources of an ECS instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*3w4m3qutCGnoYx_JyQFtMQ.png" /><figcaption>Dockerfile based on an Alpine image for running a Node.js service every 30 minutes using a cron</figcaption></figure><p>While this certainly is easy and would not require you to change your deployment code, the infrastructure cost that you would incur alone would outweigh any perceived drawbacks of switching over to a Scheduled Task.</p><h4>But why should I switch over to a Scheduled Task?</h4><p>The beauty of this method is that it will spin up the container when you need it to (based on a <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions">cron</a> or <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#RateExpressions">rate</a> expression) and automatically destroy itself once the service ends its main process.</p><p>Here are a few scenarios where you might consider using an ECS Scheduled Task over a normal ECS Task:</p><ul><li>Extract, Transform, Load (ETL) services that periodically fetch data from services or databases with varying execution times.</li><li>Application health monitoring services that periodically execute integration tests to make sure that mission-critical systems and associated third-party services are behaving as expected, again with varying execution times.</li><li>Scheduled services with an execution time greater than 15 minutes, which cannot be accommodated within the time restrictions of a serverless offering such as on AWS Lambda.</li></ul><h4>So how does a Scheduled Task work?</h4><p>Basically what happens is that the responsibility of starting a container is delegated from ECS to CloudWatch, while ECS continues to manage the container over its lifecycle once it has started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*Cj5Z9unIMkXhkACnzF1xbA.png" /><figcaption>Basic overview of how the Scheduled Task’s stack is created and managed</figcaption></figure><p>A Scheduled Task uses EventBridge (a serverless pub/sub service leveraging the CloudWatch Events API) to create an event rule on CloudWatch which then waits to be triggered by an associated cron or rate expression after which the target ECS task is invoked.</p><p>Note that the relevant service needs to exit its main process once it completes its execution in order to allow the AWS ECS Container Agent to gracefully shut it down.</p><h4>Enough reading, start deploying!</h4><p>The following is a ready-to-deploy template that can be used to create a Scheduled Task using CloudFormation and assumes (as in most scenarios) that you already have the following resources in place:</p><ul><li>An ECS cluster</li><li>A container repository (e.g. ECR or Docker Hub)</li><li>An IAM role with a policy that grants permission to the CloudWatch Events API to run tasks on ECS</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7b18edf5b1dd10e386a9ecd8c487a9e/href">https://medium.com/media/f7b18edf5b1dd10e386a9ecd8c487a9e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and </strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷 <strong>and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook</strong></a><strong> and </strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin</strong></a><strong> Groups </strong>💬<strong>.</strong></p><p><strong>To join our community Slack team chat </strong>🗣️ <strong>read our weekly Faun topics </strong>🗞️,<strong> and connect with the community </strong>📣<strong> click here⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6P3WpLjGv5v1ucm5dgkucg.png" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=520172a83a9c" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/scheduled-tasks-on-aws-ecs-520172a83a9c">Reduce your cloud infrastructure costs by using Scheduled Tasks on AWS</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>