<?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 Deepu K Sasidharan on Medium]]></title>
        <description><![CDATA[Stories by Deepu K Sasidharan on Medium]]></description>
        <link>https://medium.com/@deepu105?source=rss-28fde566f680------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*R76kmKFEbv9QHLH0.jpg</url>
            <title>Stories by Deepu K Sasidharan on Medium</title>
            <link>https://medium.com/@deepu105?source=rss-28fde566f680------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 04:00:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deepu105/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[8 important things I learned as a software developer over a decade.]]></title>
            <link>https://medium.com/@deepu105/8-important-things-i-learned-as-a-software-developer-over-a-decade-cc02398e73cf?source=rss-28fde566f680------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc02398e73cf</guid>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[pragmatic-programming]]></category>
            <category><![CDATA[code-quality]]></category>
            <dc:creator><![CDATA[Deepu K Sasidharan]]></dc:creator>
            <pubDate>Mon, 31 Aug 2020 22:00:00 GMT</pubDate>
            <atom:updated>2020-10-08T16:22:01.531Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WsGDLrYbJyoC_fkH.jpeg" /></figure><p>Please follow me on <a href="https://twitter.com/deepu105">Twitter</a> for updates and let me know what can be improved in the post.</p><p>I started my IT career, accidentally as I don’t have a Computer Science background and instead got an engineering degree in Electrical and Electronics, in March of 2010 and this year marks my 10th anniversary.</p><p>Before I start giving out any advice let me try to justify my background. In a decade-long professional software development career, I have worn several hats like Jr./Sr./Principal Developer, Tech Lead, Project Manager, Business Analyst, Pre-sales Engineer, DevOps Engineer, Cloud Engineer, OSS contributor, and finally Developer Advocate. I have also had the pleasure of co-leading an amazing open-source community behind <a href="https://www.jhipster.tech/">JHipster</a> over the past 5 years. During this period I started out as a Java/JavaScript developer and went on to work with many other languages like Go, Rust, Python, Kotlin, C#, and so on and I now consider myself a polyglot developer. I have built web applications, enterprise apps, Microservices, Cloud Native apps, CLIs, System tools, Libraries, Android and Hybrid mobile apps, and so on. Hence I hope this gives me enough experience to talk about some of the important things I learned and practiced over the last decade.</p><p>I hope this is beneficial especially to beginners and junior developers who are starting out their careers.</p><h3>1. Do not get married to a technology</h3><blockquote><em>When you marry a technology you start living with it in a bubble and you miss out on all those smart alternatives out there</em></blockquote><p>This, in my humble opinion, is the most important thing to learn for anyone starting their career. Do not get married to a programming Language, Framework, or Methodology. Getting attached to a programming language or a framework or methodology like OOP/FP will do more harm than good in the long run. Try to be pragmatic and use technology as it was intended, as a tool in your tool belt. Change is the only constant and it fits the IT industry better than others. Languages will die out, Frameworks and methodologies will come and go but the Industry will remain and anyone who is not capable of adapting to the changes may not fare well so be smart and let go of things that are dying out and learn what seems like the future.</p><h3>2. Avoid being a fanboy/fangirl</h3><p>Throughout your career, you will encounter technology that is amazing and you will fall in love with some of them. That is perfectly fine but avoid being a fanboy/fangirl and be ready to recognize something better might replace it in the future and when it does accept and move on. Trying to cling on to what you love blindly is not gonna do anyone any good. I still see fanboys of a dying language or framework making the effort to discredit the newer ones on the block, please don’t be like them its counterproductive to you and the industry.</p><h3>3. Learn the basics of programming and become a polyglot developer</h3><blockquote><em>A good programmer writes great code in a language. A great programmer is language independent.</em></blockquote><p>When learning a language learn its semantics rather than syntax. Learn programming basics. Learn about objects, collections, memory models, concurrency, and data structures. This knowledge can be applied to almost every language and the concepts around these don’t change that often. This will help you to become a true polyglot developer <a href="https://deepu.tech/how-to-be-an-effective-polyglot-developer/">which has its own merits</a> and this will help you follow the above two points as well and trust me it will make you a better developer.</p><h3>4. Write for humans</h3><blockquote><em>Any fool can write code that a computer can understand. Good programmers write code that humans can understand.</em></blockquote><blockquote><em>‒ Martin Fowler</em></blockquote><p>Write <a href="https://deepu.tech/three-tips-for-clean-code/">simple and clean code</a> and avoid showing off how smart you are in code. I know that it is tempting, especially when you are starting your career, to show off that fancy new language construct or functional magic in your code so that your colleagues can see how smart you are but trust me writing simple and easy to understand code will take you further than writing smart and complex code. Always choose the simplest solution for a problem. The best programmers are those who write the simplest code</p><p>Never discount the importance of writing good comments, documentation, and tests for your code. I know you might be tired of hearing this but I cannot stress the importance of this enough, not because I always do this but because it’s not easy to do always and I end up sacrificing this sometimes and every time I do that I have regretted that in the future. Again this is not easy but you don’t have to be 100% perfect you just need to try your best at least</p><h3>6. There is no perfect code</h3><blockquote><em>There is always a better way to do something and someone smarter to figure it out</em></blockquote><p>I used to spend a lot of time polishing my code and rewriting stuff to make it perfect, but over years I started realizing that there is nothing called perfect code, there is always a better way to do something and there is always someone smarter than you who will figure it out. I lost count of times when someone has suggested better solutions to code that I thought was perfect. Hence solve the problem at hand and avoid premature optimizations and over-engineering. One good thing about our industry is that the source code is ever-evolving and there is always tomorrow to improve it if needed. Don’t get me wrong, I’m not saying you should write sub-par code, when I say solve the problem at hand, I mean writing code that solves the issue along with all edge cases that could be thrown at it and code that is secure and with acceptable performance. I still polish my code when I feel something can be improved but I do not obsess about it or lose my sleep over it. I first get the problem solved and then if there is spare time and if an improvement helps to simplify the code or increase performance I do it. But mostly its when the polish makes code simpler.</p><h3>7. Don’t fall for trends</h3><p>We are all guilty of this, especially in our junior years. We see a hype or a trend and we get on that bandwagon without thinking through. For example, if you have React or Angular app, there is no justifiable reason IMO to switch to Vue. The same goes for many such choices which are purely based on trends, hype, or personal preferences. Don’t do something just because it’s hyped or is trendy, do what makes sense for your problem and remember something that works for a specific team need not work for another. Most companies build fancy frameworks to solve their own problem and doesn’t mean you have to blindly adapt it for no reason.</p><h3>8. Do not reinvent the wheel without a good reason</h3><blockquote><em>Not invented here (NIH) syndrome is common in IT companies and it does more harm than good</em></blockquote><p>Last but not the least make use of the collective wisdom from the industry, make use of OSS frameworks and libraries instead of building everything from scratch. There is an abundance of OSS libraries, frameworks, and tools out there for your language/platform of choice so make use of them for complex problems. Sometimes it’s better to slightly change your approach to fit a library than developing a huge library in-house just to fit your minor deviation in solution. Having said that there is also a time when you should avoid using a library, for example, it’s better to just write few lines of code as util rather than using a library for simple stuff like <a href="https://blog.npmjs.org/post/141577284765/kik-left-pad-and-npm">left pad</a> or trim. If you want to use utils from a library go for a util library like Lodash which provides multiple utilities.</p><p>There are many other things I learned over the years that have helped me but these are the important ones. Some are more common sense but its hard to recognize them especially in your initial years. The root idea is being pragmatic and using the right tools for the right job.</p><p>If you like this article, please leave a like or a comment.</p><p>You can follow me on <a href="https://twitter.com/deepu105">Twitter</a> and <a href="https://www.linkedin.com/in/deepu05/">LinkedIn</a>.</p><p>Cover image credit: Photo by <a href="https://unsplash.com/@martinkatler?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Martin Katler</a> on <a href="https://unsplash.com/s/photos/programmers-desk?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyTex">Unsplash</a></p><p><em>Also published at </em><a href="https://dev.to/deepu105/8-important-things-i-learned-as-a-software-developer-over-a-decade-4no3"><em>Dev.to</em></a></p><p><em>Originally published at </em><a href="https://deepu.tech/most-important-things-i-learned-in-a-decade/"><em>https://deepu.tech</em></a><em> on August 31, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc02398e73cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Visualizing memory management in V8 Engine (JavaScript, NodeJS, Deno, WebAssembly)]]></title>
            <link>https://medium.com/@deepu105/visualizing-memory-management-in-v8-engine-javascript-nodejs-deno-webassembly-4a18931532b9?source=rss-28fde566f680------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a18931532b9</guid>
            <category><![CDATA[v8-engine]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[webassembly]]></category>
            <dc:creator><![CDATA[Deepu K Sasidharan]]></dc:creator>
            <pubDate>Sun, 26 Jan 2020 23:23:30 GMT</pubDate>
            <atom:updated>2020-01-27T16:38:18.459Z</atom:updated>
            <content:encoded><![CDATA[<p>Please follow me on <a href="https://twitter.com/deepu105">Twitter</a> for updates and let me know if something can be improved in the post.</p><p>In this multi-part series, I aim to demystify the concepts behind memory management and take a deeper look at memory management in some of the modern programming languages. I hope the series would give you some insights into what is happening under the hood of these languages in terms of memory management.</p><p>In this chapter, we will look at the memory management of the for <a href="https://tc39.es/ecma262/">ECMAScript</a> and <a href="https://webassembly.github.io/spec/core/">WebAssembly</a>, used by runtimes like NodeJS, Deno &amp; Electron and web browsers like Chrome, Chromium, Brave, Opera, and Microsoft Edge. Since JavaScript is an interpreted language, it needs an engine to interpret and execute code. The V8 engine interprets JavaScript and compiles it down to native machine code. V8 is written in C++ and can be embedded in any C++ application.</p><p>If you haven’t read the <a href="https://dev.to/deepu105/demystifying-memory-management-in-modern-programming-languages-ddd">first part</a> of this series, please read it first as I explained the difference between the Stack and Heap memory there which would be useful to understand this chapter.</p><h3>V8 memory structure</h3><p>First, let us see what the memory structure of the V8 engine is. Since JavaScript is single-threaded V8 also uses a single process per JavaScript context and hence if you use service workers it will spawn a new V8 process per worker. A running program is always represented by some allocated memory in the V8 process and this is called <strong>Resident Set</strong>. This is further divided into different segments as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*SM_Ja0xN9q54Lpqf.png" /></figure><p>This is slightly similar to the JVM memory structure we saw in the <a href="https://dev.to/deepu105/visualizing-memory-management-in-jvm-java-kotlin-scala-groovy-clojure-19le">previous chapter</a>. Let us see what the different segments are for:</p><h4>Heap Memory</h4><p>This is where V8 stores objects or dynamic data. This is the biggest block of memory area and this is where <strong>Garbage Collection(GC)</strong> takes place. The entire heap memory is not garbage collected, only the Young and Old spare is managed by garbage collection. Heap is further divided into below:</p><ul><li><strong>New Space</strong>: New space or <strong>“Young generation”</strong> is where new objects live and most of these objects are short-lived. This space is small and has two <strong>semi-space</strong>, similar to <strong>S0</strong> &amp; <strong>S1</strong> in JVM. This space is managed by the <strong>“Scavenger(Minor GC)”</strong>, we will look at it later. The size of the new space can be controlled using the --min_semi_space_size(Initial) and --max_semi_space_size(Max) V8 flags.</li><li><strong>Old Space</strong>: Old space or <strong>“Old generation”</strong> is where objects that survived the “New space” for two minor GC cycles are moved to. This space is managed up by the <strong>Major GC(Mark-Sweep &amp; Mark-Compact)”</strong>, we will look at it later. The size of old space can be controlled using the --initial_old_space_size(Initial) and --max_old_space_size(Max) V8 flags. This space is divided into two:</li><li><strong>Old pointer space</strong>: Contains survived objects that have pointers to other objects.</li><li><strong>Old data space</strong>: Contains objects that just contain data(no pointer to other objects). Strings, boxed numbers, and arrays of unboxed doubles are moved here after surviving in “New space” for two minor GC cycles.</li><li><strong>Large object space</strong>: This is where objects which are larger than the size limits of other spaces live. Each object gets its own region of memory. Large objects are never moved by the garbage collector.</li><li><strong>Code-space</strong>: This is where the <strong>Just In Time(JIT)</strong> compiler stores compiled code Blocks. This is the only space with executable memory (although Codes may be allocated in &quot;Large object space&quot;, and those are executable, too).</li><li><strong>Cell space, property cell space, and map space</strong>: These spaces contain Cells, PropertyCells, and Maps, respectively. Each of these spaces contains objects which are all the same size and has some constraints on what kind of objects they point to, which simplifies collection.</li></ul><p>Each of these spaces is composed of a set of pages. A Page is a contiguous chunk of memory allocated from the operating system with mmap (or [MapViewOfFile](https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffile) on Windows). Each page is 1MB in size, except for Large object space.</p><h4>Stack</h4><p>This is the stack memory area and there is one stack per V8 process. This is where static data including method/function frames, primitive values, and pointers to objects are stored. The stack memory limit can be set using the --stack_size V8 flag.</p><h3>V8 memory usage (Stack vs Heap)</h3><p>Now that we are clear about how memory is organized let’s see how the most important parts of it are used when a program is executed.</p><p>Let’s use the below JavaScript program, the code is not optimized for correctness hence ignore issues like unnecessary intermediatory variables and such, the focus is to visualize stack and heap memory usage.</p><pre>class Employee {<br>    constructor(name, salary, sales) {<br>        this.name = name;<br>        this.salary = salary;<br>        this.sales = sales;<br>    }<br>}<br><br>const BONUS_PERCENTAGE = 10;<br><br>function getBonusPercentage(salary) {<br>    const percentage = (salary * BONUS_PERCENTAGE) / 100;<br>    return percentage;<br>}<br><br>function findEmployeeBonus(salary, noOfSales) {<br>    const bonusPercentage = getBonusPercentage(salary);<br>    const bonus = bonusPercentage * noOfSales;<br>    return bonus;<br>}<br><br>let john = new Employee(&quot;John&quot;, 5000, 5);<br>john.bonus = findEmployeeBonus(john.salary, john.sales);<br>console.log(john.bonus);</pre><p>Click on the slides and move forward/backward using arrow keys to see how the above program is executed and how the stack and heap memory is used:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fspeakerdeck.com%2Fplayer%2Fe89e2e48a797417eb8692897dcada584&amp;display_name=Speaker+Deck&amp;url=https%3A%2F%2Fspeakerdeck.com%2Fdeepu105%2Fv8-memory-usage-stack-and-heap&amp;image=https%3A%2F%2Ffiles.speakerdeck.com%2Fpresentations%2Fe89e2e48a797417eb8692897dcada584%2Fslide_0.jpg%3F14730960&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=speakerdeck" width="710" height="399" frameborder="0" scrolling="no"><a href="https://medium.com/media/4af985d40ee854a54c3d39ffe8d40e0a/href">https://medium.com/media/4af985d40ee854a54c3d39ffe8d40e0a/href</a></iframe><p><em>Note: If the slides look cut off at edges, then click on the title of the slide or </em><a href="https://speakerdeck.com/deepu105/v8-memory-usage-stack-and-heap"><em>here</em></a><em> to open it directly in SpeakerDeck.</em></p><p>As you can see:</p><ul><li><strong>Global scope</strong> is kept in a “Global frame” on the Stack</li><li>Every function call is added to the stack memory as a frame-block</li><li>All local variables including arguments and the return value is saved within the function frame-block on the Stack</li><li>All primitive types like int &amp; string are stored directly on the Stack. This applies to global scope as well and yes String is a primitive type in JavaScript</li><li>All object types like Employee &amp; Function are created on the Heap and is referenced from the Stack using Stack pointers. Functions are just objects in JavaScript. This applies to global scope as well</li><li>Functions called from the current function is pushed on top of the Stack</li><li>When a function returns its frame is removed from the Stack</li><li>Once the main process is complete, the objects on the Heap do not have any more pointers from Stack and becomes orphan</li><li>Unless you make a copy explicitly, all object references within other objects are done using reference pointers</li></ul><p>The Stack as you can see is automatically managed and is done so by the operating system rather than V8 itself. Hence we do not have to worry much about the Stack. The Heap, on the other hand, is not automatically managed by the OS and since its the biggest memory space and holds dynamic data, it could grow exponentially causing our program to run out of memory over time. It also becomes fragmented over time slowing down applications. This is where garbage collection comes in.</p><p>Distinguishing pointers and data on the heap is important for garbage collection and V8 uses the <strong>“Tagged pointers”</strong> approach for this — in this approach, it reserves a bit at the end of each word to indicate whether it is pointer or data. This approach requires limited compiler support, but it’s simple to implement while being fairly efficient.</p><h3>V8 Memory management: Garbage collection</h3><p>Now that we know how V8 allocates memory, let us see how it automatically manages the Heap memory which is very important for the performance of an application. When a program tries to allocate more memory on the Heap than that is freely available(depending on the V8 flags set) we encounter <strong>out of memory errors</strong>. An incorrectly managed heap could also cause a memory leak.</p><p>V8 manages the heap memory by garbage collection. In simple terms, it frees the memory used by orphan objects, i.e, objects that are no longer referenced from the Stack directly or indirectly(via a reference in another object) to make space for new object creation.</p><blockquote><strong><em>Orinoco</em></strong><em> is the codename of the V8 GC project to make use of parallel, incremental and concurrent techniques for garbage collection, to free the main thread.</em></blockquote><p>The garbage collector in V8 is responsible for reclaiming the unused memory for reuse by the V8 process.</p><p>V8 garbage collectors are generational(Objects in Heap are grouped by their age and cleared at different stages). There are two stages and three different algorithms used for garbage collection by V8:</p><h4>Minor GC (Scavenger)</h4><p>This type of GC keeps the young or new generation space compact and clean. Objects are allocated in new-space, which is fairly small (between 1 and 8 MB, depending on behavior heuristics). Allocation in “new space” is very cheap: there is an allocation pointer which we increment whenever we want to reserve space for a new object. When the allocation pointer reaches the end of the new space, minor GC is triggered. This process is also called <strong>Scavenger</strong> and it implements <a href="http://en.wikipedia.org/wiki/Cheney&#39;s_algorithm">Cheney’s algorithm</a>. It occurs frequently and uses parallel helper threads and is very fast.</p><p>Let us look at the minor GC process:</p><p>The new space is divided into two equal-sized semi-spaces: <strong>to-space</strong> and <strong>from-space</strong>. Most allocations are made in to-space (except certain kinds of objects, such as executable Codes which are always allocated in old-space). When to-space fills up the minor GC is triggered.</p><p>Click on the slides and move forward/backward using arrow keys to see the process:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fspeakerdeck.com%2Fplayer%2F5fff2548e55c4bb0a9c837c7eb598bee&amp;display_name=Speaker+Deck&amp;url=https%3A%2F%2Fspeakerdeck.com%2Fdeepu105%2Fv8-minor-gc&amp;image=https%3A%2F%2Fspeakerd.s3.amazonaws.com%2Fpresentations%2F5fff2548e55c4bb0a9c837c7eb598bee%2Fslide_0.jpg%3F596090&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=speakerdeck" width="710" height="399" frameborder="0" scrolling="no"><a href="https://medium.com/media/6405d9a2bd3d42ff81c81f3d99b5cd06/href">https://medium.com/media/6405d9a2bd3d42ff81c81f3d99b5cd06/href</a></iframe><p><em>Note: If the slides look cut off at edges, then click on the title of the slide or </em><a href="https://speakerdeck.com/deepu105/v8-minor-gc"><em>here</em></a><em> to open it directly in SpeakerDeck.</em></p><ol><li>Let us assume that there are already objects on the “to-space” when we start(Blocks 01 to 06 marked as used memory)</li><li>The process creates a new object(07)</li><li>V8 tries to get required memory from to-space, but there is no free space in there to accommodate our object and hence V8 triggers minor GC</li><li>Minor GC swaps the “to-space” and “from-space”, all the objects are now in “from-space” and the “to-space” is empty</li><li>Minor GC recursively traverses the object graph in “from-space” starting from stack pointers(GC roots) to find objects that are used or alive(Used memory). These objects are moved to a page in the “to-space”. Any objects reference by these objects are also moved to this page in “to-space” and their pointers are updated. This is repeated until all the objects in “from-space” are scanned. By end of this, the “to-space” is automatically compacted reducing fragmentation</li><li>Minor GC now empties the “from-space” as any remaining object here is garbage</li><li>The new object is allocated memory in the “to-space”</li><li>Let us assume that some time has passed and there are more objects on the “to-space” now(Blocks 07 to 09 marked as used memory)</li><li>The application creates a new object(10)</li><li>V8 tries to get required memory from “to-space”, but there is no free space in there to accommodate our object and hence V8 triggers second minor GC</li><li>The above process is repeated and any alive objects that survived second minor GC is moved to the “Old space”. First-time survivors are moved to the “to-space” and remaining garbage is cleared from “from-space”</li><li>The new object is allocated memory in the “to-space”</li></ol><p>So we saw how minor GC reclaims space from the young generation and keeps it compact. It is a stop-the-world process but it’s so fast and efficient that it is negligible most of the time. Since this process doesn’t scan objects in the “old space” for any reference in the “new space” it uses a register of all pointers from old space to new space. This is recorded to the store buffer by a process called <a href="https://www.memorymanagement.org/glossary/w.html#term-write-barrier"><strong>write barriers</strong></a>.</p><h4>Major GC</h4><p>This type of GC keeps the old generation space compact and clean. This is triggered when V8 decides there is not enough old space, based on a dynamically computed limit, as it gets filled up from minor GC cycles.</p><p>The Scavenger algorithm is perfect for small data size but is impractical for large heap, as the old space, as it has memory overhead and hence major GC is done using the <strong>Mark-Sweep-Compact</strong> algorithm. It uses a <strong>tri-color</strong>(white-grey-black) marking system. Hence major GC is a three-step process and the third step is executed depending on a fragmentation heuristic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*5cyzEpak2KthNN0U.gif" /></figure><ul><li><strong>Marking</strong>: First step, common for both algorithms, where garbage collector identifies which objects are in use and which ones are not in use. The objects in use or reachable from GC roots(Stack pointers) recursively are marked as alive. It’s technically a depth-first-search of the heap which can be considered as a directed graph</li><li><strong>Sweeping</strong>: The garbage collector traverses the heap and makes note of the memory address of any object that is not marked alive. This space is now marked as free in the free-list and can be used to store other objects</li><li><strong>Compacting</strong>: After sweeping, if required, all the survived objects will be moved to be together. This will decrease fragmentation and increase the performance of allocation of memory to newer objects</li></ul><p>This type of GC is also referred to us stop-the-world GC as they introduce pause-times in the process while performing GC. To avoid this V8 uses techniques like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*1FzmXNI6mIXKdOEi-mbTOw.png" /></figure><ul><li><strong>Incremental GC</strong>: GC is done in multiple incremental steps instead of one.</li><li><strong>Concurrent marking</strong>: Marking is done concurrently using multiple helper threads without affecting the main JavaScript thread. Write barriers are used to keep track of new references between objects that JavaScript creates while the helpers are marking concurrently.</li><li><strong>Concurrent sweeping/compacting</strong>: Sweeping and compacting are done in helper threads concurrently without affecting the main JavaScript thread.</li><li><strong>Lazy sweeping</strong>. Lazy sweeping involves delaying the deletion of garbage in pages until the memory is required.</li></ul><p>Let us look at the major GC process:</p><ol><li>Let us assume that many minor GC cycles have passed and the old space is almost full and V8 decides to trigger a “Major GC”</li><li>Major GC recursively traverses the object graph starting from stack pointers to mark objects that are used as alive(Used memory) and remaining objects as garbage(Orphans) in the old space. This is done using multiple concurrent helper threads and each helper follows a pointer. This does not affect the main JS thread.</li><li>When concurrent marking is done or if memory limit is reached the GC does a mark finalization step using the main thread. This introduces a small pause-time.</li><li>Major GC now marks all orphan object’s memory as free using concurrent sweep threads. Parallel compaction tasks are also triggered to move related blocks of memory to the same page to avoid fragmentation. Pointers are updated during these steps.</li></ol><h3>Conclusion</h3><p>This post should give you an overview of the V8 memory structure and memory management. This is not exhaustive, there are a lot more advanced concepts and you can learn about them from <a href="https://v8.dev/blog/trash-talk">v8.dev</a>. But for most JS/WebAssembly developers this level of information would be sufficient and I hope it helps you write better code, considering these in mind, for more performant applications and keeping these in mind would help you to avoid the next memory leak issue you might encounter otherwise.</p><h3>References</h3><ul><li><a href="https://v8.dev/blog/trash-talk">https://v8.dev/blog/trash-talk</a></li><li><a href="http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection">http://jayconrod.com</a></li><li><a href="https://blog.codeship.com/understanding-garbage-collection-in-node-js/">https://blog.codeship.com</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management">https://developer.mozilla.org</a></li><li><a href="https://blog.sessionstack.com/how-javascript-works-memory-management-how-to-handle-4-common-memory-leaks-3f28b94cfbec">https://blog.sessionstack.com</a></li></ul><p>I hope you had fun learning about the V8 internals, stay tuned for the next post in the series.</p><p>If you like this article, please leave a like or a comment.</p><p>You can follow me on <a href="https://twitter.com/deepu105">Twitter</a> and <a href="https://www.linkedin.com/in/deepu05/">LinkedIn</a>.</p><p><em>Also published on </em><a href="https://deepu.tech/memory-management-in-v8/"><em>my blog</em></a><em> and </em><a href="https://dev.to/deepu105/visualizing-memory-management-in-v8-engine-javascript-nodejs-deno-webassembly-105p"><em>https://dev.to</em></a><em> on January 26, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a18931532b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Visualizing memory management in JVM(Java, Kotlin, Scala, Groovy, Clojure)]]></title>
            <link>https://medium.com/@deepu105/visualizing-memory-management-in-jvm-java-kotlin-scala-groovy-clojure-4fbcc0929482?source=rss-28fde566f680------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fbcc0929482</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[clojure]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[memory-management]]></category>
            <dc:creator><![CDATA[Deepu K Sasidharan]]></dc:creator>
            <pubDate>Wed, 22 Jan 2020 23:00:00 GMT</pubDate>
            <atom:updated>2020-01-27T16:39:28.347Z</atom:updated>
            <content:encoded><![CDATA[<p>Please follow me on <a href="https://twitter.com/deepu105">Twitter</a> for updates and let me know if something can be improved in the post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*f_1ssMEnT6gamEF-.gif" /></figure><p>In this multi-part series, I aim to demystify the concepts behind memory management and take a deeper look at memory management in some of the modern programming languages. I hope the series would give you some insights into what is happening under the hood of these languages in terms of memory management. In this chapter, we will look at the memory management of the <strong>Java Virtual Machine(JVM)</strong> used by languages like Java, Kotlin, Scala, Clojure, JRuby and so on.</p><p>If you haven’t read the <a href="https://deepu.tech/memory-management-in-programming/">first part</a> of this series, please read it first as I explained the difference between the Stack and Heap memory there which would be useful to understand this chapter.</p><h3>JVM memory structure</h3><p>First, let us see what the memory structure of JVM is. This is based on <strong>JDK 11</strong> onwards. Below is the memory available to a JVM process and is allocated by the Operating System(OS).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*n656QM9UvlNwwyav.png" /></figure><p>This is the native memory allocated by the OS and the amount depends on OS, processor, and JRE. Let us see what the different areas are for:</p><h4>Heap Memory</h4><p>This is where JVM stores objects or dynamic data. This is the biggest block of memory area and this is where <strong>Garbage Collection(GC)</strong> takes place. The size of heap memory can be controlled using the Xms(Initial) and Xmx(Max) flags. The entire heap memory is not committed to the <strong>Virtual Machine(VM)</strong> as some of it is reserved as virtual space and the heap can grow to use this. Heap is further divided into <strong>&quot;Young&quot;</strong> and <strong>&quot;Old&quot;</strong> generation space.</p><ul><li><strong>Young generation</strong>: Young generation or “New Space” is where new objects live and is further divided into “Eden Space” and “Survivor Space”. This space is managed by <strong>“Minor GC”</strong> also sometimes called “Young GC”. <strong>Eden Space</strong>: This is where new objects are created. When we create a new object, memory is allocated here. <strong>Survivor Space</strong>: This is where objects that survived the minor GC are stored. This is divided into two halves, <strong>S0</strong> and <strong>S1</strong>.</li><li><strong>Old generation</strong>: Old generation or <strong>“Tenured Space”</strong> is where objects that reached the maximum tenure threshold during minor GC live. This space is managed up by <strong>“Major GC”</strong>.</li></ul><h4>Thread Stacks</h4><p>This is the stack memory area and there is one stack memory per thread in the process. This is where thread-specific static data including method/function frames and pointers to objects are stored. The stack memory limit can be set using the Xss flag.</p><h4>Meta Space</h4><p>This is part of the native memory and doesn’t have an upper limit by default. This is what used to be <strong>Permanent Generation(PermGen) Space</strong> in earlier versions of JVM. This space is used by the class loaders to store class definitions. If this space keeps growing, the OS might move data stored here from RAM to virtual memory which might slow down the application. To avoid that its possible to set a limit on meta space used with the XX:MetaspaceSize and -XX:MaxMetaspaceSize flag in which case application might just throw out of memory errors.</p><h4>Code Cache</h4><p>This is where the <strong>Just In Time(JIT)</strong> compiler stores compiled code blocks that are often accessed. Generally, JVM has to interpret byte code to native machine code whereas JIT-compiled code need not be interpreted as it is already in native format and is cached here.</p><h4>Shared Libraries</h4><p>This is where native code for any shared libraries used are stored. This is loaded only once per process by the OS.</p><h3>JVM memory usage (Stack vs Heap)</h3><p>Now that we are clear about how memory is organized let’s see how the most important parts of it are used when a program is executed.</p><p>Let’s use the below Java program, the code is not optimized for correctness hence ignore issues like unnecessary intermediatory variables, improper modifiers and such, the focus is to visualize stack and heap memory usage.</p><pre>class Employee {<br>    String name;<br>    Integer salary;<br>    Integer sales;<br>    Integer bonus;<br><br>    public Employee(String name, Integer salary, Integer sales) {<br>        this.name = name;<br>        this.salary = salary;<br>        this.sales = sales;<br>    }<br>}<br><br>public class Test {<br>    static int BONUS_PERCENTAGE = 10;<br><br>    static int getBonusPercentage(int salary) {<br>        int percentage = salary * BONUS_PERCENTAGE / 100;<br>        return percentage;<br>    }<br><br>    static int findEmployeeBonus(int salary, int noOfSales) {<br>        int bonusPercentage = getBonusPercentage(salary);<br>        int bonus = bonusPercentage * noOfSales;<br>        return bonus;<br>    }<br><br>    public static void main(String[] args) {<br>        Employee john = new Employee(&quot;John&quot;, 5000, 5);<br>        john.bonus = findEmployeeBonus(john.salary, john.sales);<br>        System.out.println(john.bonus);<br>    }<br>}</pre><p>Click on the slides and move forward/backward using arrow keys to see how the above program is executed and how the stack and heap memory is used:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fspeakerdeck.com%2Fplayer%2F9780d352c95f4361bd8c6fa164554afc&amp;display_name=Speaker+Deck&amp;url=https%3A%2F%2Fspeakerdeck.com%2Fdeepu105%2Fjvm-memory-usage-stack-vs-heap&amp;image=https%3A%2F%2Fspeakerd.s3.amazonaws.com%2Fpresentations%2F9780d352c95f4361bd8c6fa164554afc%2Fslide_0.jpg%3F594730&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=speakerdeck" width="710" height="399" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa2058ecc13be34c1655aa27fe8af129/href">https://medium.com/media/aa2058ecc13be34c1655aa27fe8af129/href</a></iframe><p><em>Note: If the slides look cut off at edges, then click on the title of the slide or </em><a href="https://speakerdeck.com/deepu105/jvm-memory-usage-stack-vs-heap"><em>here</em></a><em> to open it directly in SpeakerDeck.</em></p><p>As you can see:</p><ul><li><strong>Static fields</strong> are kept in a separate block on the Stack</li><li>Every function call is added to the thread’s stack memory as a frame-block</li><li>All local variables including arguments and the return value is saved within the function frame-block on the Stack</li><li>All primitive types like int are stored directly on the Stack. This applies to static fields as well</li><li>All object types like Employee, Integer, String are created on the Heap and is referenced from the Stack using Stack pointers. This applies to static fields as well</li><li>Functions called from the current function is pushed on top of the Stack</li><li>When a function returns its frame is removed from the Stack</li><li>Once the main process is complete the objects on the Heap do not have any more pointers from Stack and becomes orphan</li><li>Unless you make a copy explicitly, all object references within other objects are done using pointers</li></ul><p>The Stack as you can see is automatically managed and is done so by the operating system rather than JVM itself. Hence we do not have to worry much about the Stack. The Heap, on the other hand, is not automatically managed by the OS and since its the biggest memory space and holds dynamic data, it could grow exponentially causing our program to run out of memory over time. It also becomes fragmented over time slowing down applications. This is where the JVM helps. It manages the Heap automatically using the garbage collection process.</p><h3>JVM Memory management: Garbage collection</h3><p>Now that we know how JVM allocates memory, let us see how it automatically manages the Heap memory which is very important for the performance of an application. When a program tries to allocate more memory on the Heap than that is freely available(depending on the Xmx config) we encounter <strong>out of memory errors</strong>.</p><p>JVM manages the heap memory by garbage collection. In simple terms, it frees the memory used by orphan objects, i.e, objects that are no longer referenced from the Stack directly or indirectly(via a reference in another object) to make space for new object creation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/0*j-QHiOV2vRk-7AQE.png" /></figure><p>The garbage collector in JVM is responsible for:</p><ul><li>Memory allocation from OS and back to OS.</li><li>Handing out allocated memory to the application as it requests it.</li><li>Determining which parts of the allocated memory is still in use by the application.</li><li>Reclaiming the unused memory for reuse by the application.</li></ul><p>JVM garbage collectors are generational(Objects in Heap are grouped by their age and cleared at different stages). There are many different algorithms available for garbage collection but <strong>Mark &amp; Sweep</strong> is the most commonly used one.</p><h3>Mark &amp; Sweep Garbage collection</h3><p>JVM uses a separate daemon thread that runs in the background for garbage collection and the process runs when certain conditions are met. Mark &amp; Sweep GC generally involves two phases and sometimes there is an optional third phase depending on the algorithm used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/0*hSkCTFU1bZMm0dFx.gif" /></figure><ul><li><strong>Marking</strong>: First step where garbage collector identifies which objects are in use and which ones are not in use. The objects in use or reachable from GC roots(Stack pointers) recursively are marked as alive.</li><li><strong>Sweeping</strong>: The garbage collector traverses the heap and removes any object that is not marked alive. This space is now marked as free.</li><li><strong>Compacting</strong>: After deleting unused objects, all the survived objects will be moved to be together. This will decrease fragmentation and increase the performance of allocation of memory to newer objects</li></ul><p>This type of GC is also referred to us stop-the-world GC as they introduce pause-times in the application while performing GC.</p><p>JVM offers few different algorithms to choose from when it comes to GC and there might be few more options available depending on the JDK vendor you use(Like the <a href="https://wiki.openjdk.java.net/display/shenandoah/Main">Shenandoah GC</a>, available on OpenJDK). The different implementations focus on different goals like:</p><ul><li><strong>Throughput</strong>: Time spent collecting garbage instead of application time affects throughput. The throughput ideally should be high(I.e when GC times are low).</li><li><strong>Pause-time</strong>: The duration for which GC stops the application from executing. The pause-time ideally should be very low.</li><li><strong>Footprint</strong>: Size of the heap used. This ideally should be kept low.</li></ul><h4>Collectors available as of JDK 11</h4><p>As of JDK 11, which is the current LTE version, the below garbage collectors are available and the default used is chosen by JVM based on hardware and OS used. We can always specify the GC to be used with the -XX switch as well.</p><ul><li><strong>Serial Collector</strong>: It uses a single thread for GC and is efficient for applications with small data sets and is most suitable for single-processor machines. This can be enabled using -XX:+UseSerialGC switch.</li><li><strong>Parallel Collector</strong>: This one is focused on high throughput and uses multiple threads to speed up the GC process. This is intended for applications with medium to large data sets running on multi-threaded/multi-processor hardware. This can be enabled using -XX:+UseParallelGC switch.</li><li><strong>Garbage-First(G1) Collector</strong>: The G1 collector is a mostly concurrent collector(Means only expensive work is done concurrently). This is for multi-processor machines with a large amount of memory and is enabled as default on most modern machines and OS. It has a focus on low pause-times and high throughput. This can be enabled using -XX:+UseG1GC switch.</li><li><strong>Z Garbage Collector</strong>: This is a new experimental GC introduced in JDK11. It is a scalable low-latency collector. It’s concurrent and does not stop the execution of application threads, hence no stop-the-world. It is intended for applications that require low latency and/or use a very large heap(multi-terabytes). This can be enabled using -XX:+UseZGC switch.</li></ul><h3>GC process</h3><p>Regardless of the collector used, JVM has two types of GC process depending on when and where its performed, the minor GC and major GC.</p><h4>Minor GC</h4><p>This type of GC keeps the young generation space compact and clean. This is triggered when below conditions are met:</p><p>Initially, all the areas of heap space are empty. Eden memory is the first one to be filled, followed by survivor space and finally by tenured space.</p><p>Let us look at the minor GC process:</p><p>Click on the slides and move forward/backward using arrow keys to see the process:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fspeakerdeck.com%2Fplayer%2Ff4783404769145f4b990154d0cc05629&amp;display_name=Speaker+Deck&amp;url=https%3A%2F%2Fspeakerdeck.com%2Fdeepu105%2Fjvm-minor-gc&amp;image=https%3A%2F%2Fspeakerd.s3.amazonaws.com%2Fpresentations%2Ff4783404769145f4b990154d0cc05629%2Fslide_0.jpg%3F595230&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=speakerdeck" width="710" height="399" frameborder="0" scrolling="no"><a href="https://medium.com/media/6760e443582cdeabf6d215593af3f9b3/href">https://medium.com/media/6760e443582cdeabf6d215593af3f9b3/href</a></iframe><p><em>Note: If the slides look cut off at edges, then click on the title of the slide or </em><a href="https://speakerdeck.com/deepu105/jvm-minor-gc"><em>here</em></a><em> to open it directly in SpeakerDeck.</em></p><ol><li>Let us assume that there are already objects on the Eden space when we start(Blocks 01 to 06 marked as used memory)</li><li>The application creates a new object(07)</li><li>JVM tries to get required memory from Eden space, but there is no free space in Eden to accommodate our object and hence JVM triggers minor GC</li><li>The GC recursively traverses the object graph starting from stack pointers to mark objects that are used as alive(Used memory) and remaining objects as garbage(Orphans)</li><li>JVM chooses one random block from S0 and S1 as the “To Space”, let’s assume it was S0. The GC now moves all the alive objects into the “To Space”, S0, which was empty when we started and increments their age by one.</li><li>The GC now empties the Eden space and the new object is allocated memory in the Eden space</li><li>Let us assume that some time has passed and there are more objects on the Eden space now(Blocks 07 to 13 marked as used memory)</li><li>The application creates a new object(14)</li><li>JVM tries to get required memory from Eden space, but there is no free space in Eden to accommodate our object and hence JVM triggers second minor GC</li><li>The mark phase is repeated and alive/orphan objects are marked including the ones in survivor space “To Space”</li><li>JVM chooses the free S1 as the “To Space” now and S0 becomes “From Space”. The GC now moves all the alive objects from Eden space and the “From Space”, S0, into the “To Space”, S1, which was empty when we started and increments their age by one. Since some objects don’t fit here, they are moved to the “Tenured Space” as the survivor space cannot grow and this process is called premature promotion. This can happen even if one of the survivor space is free</li><li>The GC now empties the Eden space and the “From Space”, S0, and the new object is allocated memory in the Eden space</li><li>This keeps on repeating for each minor GC and the survivors are shifted between S0 and S1 and their age is incremented. Once the age reaches the “max-age threshold”, 15 by default, the object is moved to the “Tenured space”</li></ol><p>So we saw how minor GC reclaims space from the young generation. It is a stop-the-world process but it’s so fast that it is negligible most of the time.</p><h4>Major GC</h4><p>This type of GC keeps the old generation(Tenured) space compact and clean. This is triggered when below conditions are met:</p><ul><li>Developer calls System.gc(), or Runtime.getRunTime().gc() from the program.</li><li>JVM decides there is not enough tenured space as it gets filled up from minor GC cycles.</li><li>During minor GC, if the JVM is not able to reclaim enough memory from the Eden or survivor spaces.</li><li>If we set a MaxMetaspaceSize option for the JVM and there is not enough space to load new classes.</li></ul><p>Let us look at the major GC process, it’s not as complex as minor GC:</p><ol><li>Let us assume that many minor GC cycles have passed and the tenured space is almost full and JVM decides to trigger a “Major GC”</li><li>The GC recursively traverses the object graph starting from stack pointers to mark objects that are used as alive(Used memory) and remaining objects as garbage(Orphans) in the tenured space. If the major GC was triggered during a minor GC the process includes the young(Eden &amp; Survivor) and tenured space</li><li>The GC now removed all orphan objects and reclaims the memory</li><li>During a major GC event, if there are no more objects in the Heap, the JVM reclaims memory from the meta-space as well by removing loaded classes from it this is also referred to as full GC</li></ol><h3>Conclusion</h3><p>This post should give you an overview of the JVM memory structure and memory management. This is not exhaustive, there are a lot more advanced concepts and tuning options available for specific use cases and you can learn about them from <a href="https://docs.oracle.com/en/java/javase/13/gctuning/">https://docs.oracle.com</a>. But for most JVM(Java, Kotlin, Scala, Clojure, JRuby, Jython) developers this level of information would be sufficient and I hope it helps you write better code, considering these in mind, for more performant applications and keeping these in mind would help you to avoid the next memory leak issue you might encounter otherwise.</p><p>I hope you had fun learning about the JVM internals, stay tuned for the next post in the series.</p><h3>References</h3><ul><li><a href="https://docs.oracle.com/en/java/javase/13/gctuning/">https://docs.oracle.com</a></li><li><a href="http://pythontutor.com/java.html">http://pythontutor.com/java.html</a></li><li><a href="https://www.journaldev.com/2856/java-jvm-memory-model-memory-management-in-java">https://www.journaldev.com</a></li><li><a href="https://www.yourkit.com/docs/kb/sizes.jsp">https://www.yourkit.com</a></li><li><a href="https://dzone.com/articles/understanding-the-java-memory-model-and-the-garbag/">https://dzone.com</a></li><li><a href="https://www.infoq.com/articles/Visualizing-Java-Garbage-Collection/">https://www.infoq.com</a></li></ul><p>If you like this article, please leave a like or a comment.</p><p>You can follow me on <a href="https://twitter.com/deepu105">Twitter</a> and <a href="https://www.linkedin.com/in/deepu05/">LinkedIn</a>.</p><p><em>Also published on </em><a href="https://dev.to/deepu105/visualizing-memory-management-in-jvm-java-kotlin-scala-groovy-clojure-19le"><em>Dev.to</em></a></p><p><em>Originally published at </em><a href="https://deepu.tech/memory-management-in-jvm/"><em>https://deepu.tech</em></a><em> on January 22, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fbcc0929482" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Demystifying memory management in modern programming languages]]></title>
            <link>https://medium.com/@deepu105/demystifying-memory-management-in-modern-programming-languages-c35df98cb726?source=rss-28fde566f680------2</link>
            <guid isPermaLink="false">https://medium.com/p/c35df98cb726</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[garbage-collection]]></category>
            <category><![CDATA[memory-management]]></category>
            <dc:creator><![CDATA[Deepu K Sasidharan]]></dc:creator>
            <pubDate>Tue, 07 Jan 2020 23:00:00 GMT</pubDate>
            <atom:updated>2020-01-27T15:20:38.363Z</atom:updated>
            <content:encoded><![CDATA[<p>Please follow me on <a href="https://twitter.com/deepu105">Twitter</a> for updates and let me know if something can be improved in the post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8an4j3v7Pk_XG_uM.png" /></figure><p>In this multi-part series, I aim to demystify the concepts behind memory management and take a deeper look at memory management in some of the modern programming languages. I hope the series would give you some insights into what is happening under the hood of these languages in terms of memory management. Learning about memory management will also help us to write more performant code as the way we write code also has an impact on memory management regardless of the automatic memory management technique used by the language.</p><h3>Part 1: Introduction to Memory management</h3><p>Memory management is the process of controlling and coordinating the way a software application access <strong>computer memory</strong>. It is a serious topic in software engineering and its a topic that confuses some people and is a black box for some.</p><h3>What is it?</h3><p>When a software runs on a target Operating system on a computer it needs access to the computers <strong>RAM</strong>(Random-access memory) to:</p><ul><li>load its own <strong>bytecode</strong> that needs to be executed</li><li>store the <strong>data values</strong> and <strong>data structures</strong> used by the program that is executed</li><li>load any <strong>run-time systems</strong> that are required for the program to execute</li></ul><p>When a software program uses memory there are two regions of memory they use, apart from the space used to load the bytecode, Stack and Heap memory.</p><h4>Stack</h4><p>The stack is used for <strong>static memory allocation</strong> and as the name suggests it is a last in first out( <strong>LIFO</strong>) stack (Think of it as a stack of boxes).</p><ul><li>Due to this nature, the process of storing and retrieving data from the stack is <strong>very fast</strong> as there is no lookup required, you just store and retrieve data from the topmost block on it.</li><li>But this means any data that is stored on the stack has to be <strong>finite and static</strong>(The size of the data is known at compile-time).</li><li>This is where the execution data of the functions are stored as <strong>stack frames</strong>(So, this is the actual execution stack). Each frame is a block of space where the data required for that function is stored. For example, every time a function declares a new variable, it is “pushed” onto the topmost block in the stack. Then every time a function exits, the topmost block is cleared, thus all of the variables pushed onto the stack by that function, are cleared. These can be determined at compile time due to the static nature of the data stored here.</li><li><strong>Multi-threaded applications</strong> can have a <strong>stack per thread</strong>.</li><li>Memory management of the stack is <strong>simple and straightforward</strong> and is done by the OS.</li><li>Typical data that are stored on stack are <strong>local variables</strong>(value types or primitives, primitive constants), <strong>pointers</strong> and <strong>function frames</strong>.</li><li>This is where you would encounter <strong>stack overflow errors</strong> as the size of the stack is limited compared to the Heap.</li><li>There is a <strong>limit on the size</strong> of value that can be stored on the Stack for most languages.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VNC2Yvwf61wFdb3o.gif" /></figure><p>Stack used in JavaScript, objects are stored in Heap and referenced when needed. <a href="https://youtu.be/95_CAUC9nvE">Here </a>is a video of the same.</p><h4>Heap</h4><p>Heap is used for <strong>dynamic memory allocation</strong> and unlike stack, the program needs to look up the data in heap using <strong>pointers</strong> (Think of it as a big multi-level library).</p><ul><li>It is <strong>slower</strong> than stack as the process of looking up data is more involved but it can store more data than the stack.</li><li>This means data with <strong>dynamic size</strong> can be stored here.</li><li>Heap is <strong>shared</strong> among threads of an application.</li><li>Due to its dynamic nature heap is <strong>trickier to manage</strong> and this is where most of the memory management issues arise from and this is where the automatic memory management solutions from the language kick in.</li><li>Typical data that are stored on the heap are <strong>global variables</strong>, <strong>reference types</strong> like objects, strings, maps, and other complex data structures.</li><li>This is where you would encounter <strong>out of memory errors</strong> if your application tries to use more memory than the allocated heap(Though there are many other factors at play here like GC, compacting).</li><li>Generally, there is <strong>no limit</strong> on the size of the value that can be stored on the heap. Of course, there is the upper limit of how much memory is allocated to the application.</li></ul><h3>Why is it important?</h3><p>Unlike Hard disk drives, RAM is not infinite. If a program keeps on consuming memory without freeing it, ultimately it will run out of memory and crash itself or even worse crash the operating system. Hence software programs can’t just keep using RAM as they like as it will cause other programs and processes to run out of memory. So instead of letting the software developer figure this out, most programming languages provide ways to do automatic memory management. And when we talk about memory management we are mostly talking about managing the Heap memory.</p><h3>Different approaches?</h3><p>Since modern programming languages don’t want to burden(more like trust 👅) the end developer to manage the memory of his/her application most of them have devised a way to do automatic memory management. Some older languages still require manual memory handling but many do provide neat ways to do that. Some languages use multiple approaches to memory management and some even let the developer choose what is best for him/her(C++ is a good example). The approaches can be categorized as below</p><h4>Manual memory management</h4><p>The language doesn’t manage memory for you by default, it’s up to you to allocate and free memory for the objects you create. For example, <strong>C</strong> and <strong>C++</strong>. They provide the malloc, realloc, calloc, and free methods to manage memory and it&#39;s up to the developer to allocate and free heap memory in the program and make use of pointers efficiently to manage memory. Let&#39;s just say that it&#39;s not for everyone 😉.</p><h4>Garbage collection(GC)</h4><p>Automatic management of heap memory by freeing unused memory allocations. GC is one of the most common memory management in modern languages and the process often runs at certain intervals and thus might cause a minor overhead called pause times. <strong>JVM(Java/Scala/Groovy/Kotlin)</strong>, <strong>JavaScript</strong>, <strong>C#</strong>, <strong>Golang</strong>, <strong>OCaml</strong>, and <strong>Ruby</strong> are some of the languages that use Garbage collection for memory management by default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/0*uEs0DdQQW-1qEcMJ.gif" /></figure><ul><li><strong>Mark &amp; Sweep GC</strong>: Also known as Tracing GC. Its generally a two-phase algorithm that first marks objects that are still being referenced as “alive” and in the next phase frees the memory of objects that are not alive. <strong>JVM</strong>, <strong>C#</strong>, <strong>Ruby</strong>, <strong>JavaScript</strong>, and <strong>Golang</strong> employ this approach for example. In JVM there are different GC algorithms to choose from while JavaScript engines like V8 use a Mark &amp; Sweep GC along with Reference counting GC to complement it. This kind of GC is also available for C &amp; C++ as an <a href="https://en.wikipedia.org/wiki/Boehm_garbage_collector">external library</a>.</li><li><strong>Reference counting GC</strong>: In this approach, every object gets a reference count which is incremented or decremented as references to it change and garbage collection is done when the count becomes zero. It’s not very preferred as it cannot handle cyclic references. <strong>PHP</strong>, <strong>Perl</strong>, and <strong>Python</strong>, for example, uses this type of GC with workarounds to overcome cyclic references. This type of GC can be enabled for C++ as well.</li></ul><h4>Resource Acquisition is Initialization (RAII)</h4><p>In this type of memory management, an object’s memory allocation is tied to its lifetime, which is from construction until destruction. It was introduced in <strong>C++</strong> and is also used by <strong>Ada</strong> and <strong>Rust</strong>.</p><h4>Automatic Reference Counting(ARC)</h4><p>It&#39;s similar to Reference counting GC but instead of running a runtime process at a specific interval the retain and release instructions are inserted to the compiled code at compile-time and when an object reference becomes zero its cleared automatically as part of execution without any program pause. It also cannot handle cyclic references and relies on the developer to handle that by using certain keywords. Its a feature of the Clang compiler and provides ARC for <strong>Objective C</strong> &amp; <strong>Swift</strong>.</p><h4>Ownership</h4><p>It combines RAII with an ownership model, any value must have a variable as its owner(and only one owner at a time) when the owner goes out of scope the value will be dropped freeing the memory regardless of it being in stack or heap memory. It is kind of like Compile-time reference counting. It is used by <a href="https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html"><strong>Rust</strong></a>, in my research I couldn’t find any other language using this exact mechanism.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ArQ5s-bYrQ_c9aiu.png" /></figure><p>We have just scratched the surface of memory management. Each programming language uses its own version of these and employs different algorithms tuned for different goals. In the next parts of the series, we will take a closer look at the exact memory management solution in some of the popular languages.</p><p>Stay tuned for upcoming parts of this series:</p><ul><li><a href="https://dev.to/deepu105/visualizing-memory-management-in-jvm-java-kotlin-scala-groovy-clojure-19lecu">Part 2: Memory management in JVM(Java, Kotlin, Scala, Groovy)</a></li><li><a href="https://dev.to/deepu105/visualizing-memory-management-in-v8-engine-javascript-nodejs-deno-webassembly-105p">Part 3: Memory management in V8(JavaScript/WebAssembly)</a></li><li>Part 4: Memory management in Go</li><li>Part 5: Memory management in Rust</li><li>Part 6: Memory management in Python</li><li>Part 7: Memory management in C++</li><li>Part 8: Memory management in C#</li></ul><h3>References</h3><ul><li><a href="http://homepages.inf.ed.ac.uk/stg/teaching/apl/handouts/memory.pdf">http://homepages.inf.ed.ac.uk</a></li><li><a href="https://javarevisited.blogspot.com/2013/01/difference-between-stack-and-heap-java.html?m=1">https://javarevisited.blogspot.com</a></li><li><a href="http://net-informations.com/faq/net/stack-heap.htm">http://net-informations.com</a></li><li><a href="https://gribblelab.org/CBootCamp/7_Memory_Stack_vs_Heap.html">https://gribblelab.org</a></li><li><a href="https://medium.com/computed-comparisons/garbage-collection-vs-automatic-reference-counting-a420bd4c7c81">https://medium.com/computed-comparisons</a></li><li><a href="https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)">https://en.wikipedia.org/wiki/Garbage*collection*(computer_science)</a></li><li><a href="https://en.wikipedia.org/wiki/Automatic_Reference_Counting">https://en.wikipedia.org/wiki/Automatic_Reference_Counting</a></li><li><a href="https://blog.sessionstack.com/how-javascript-works-memory-management-how-to-handle-4-common-memory-leaks-3f28b94cfbec">https://blog.sessionstack.com/</a></li></ul><p>If you like this article, please leave a like or a comment.</p><p>You can follow me on <a href="https://twitter.com/deepu105">Twitter</a> and <a href="https://www.linkedin.com/in/deepu05/">LinkedIn</a>.</p><p>Image credits: Stack visualization: Created based on <a href="http://pythontutor.com/javascript.html#mode=display">pythontutor</a>. Ownership illustration: <a href="https://hacks.mozilla.org/2018/12/rust-2018-is-here/">Link Clark, The Rust team</a> under <a href="https://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution Share-Alike License v3.0</a>.</p><p><em>Also published on </em><a href="https://dev.to/deepu105/demystifying-memory-management-in-modern-programming-languages-ddd"><em>Dev.to</em></a></p><p><em>Originally published at </em><a href="https://deepu.tech/memory-management-in-programming/"><em>https://deepu.tech</em></a><em> on January 7, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c35df98cb726" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My beautiful Linux development environment]]></title>
            <link>https://medium.com/@deepu105/my-beautiful-linux-development-environment-d96d4e4e2f62?source=rss-28fde566f680------2</link>
            <guid isPermaLink="false">https://medium.com/p/d96d4e4e2f62</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[fedora]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[gnome]]></category>
            <dc:creator><![CDATA[Deepu K Sasidharan]]></dc:creator>
            <pubDate>Sun, 16 Jun 2019 13:38:55 GMT</pubDate>
            <atom:updated>2019-07-13T13:13:57.480Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cpD8ZgG2qRDMuUpZniqbtA.png" /></figure><p>One of the questions that I get quite often after a conference talk is weirdly not about what I presented but about my Linux desktop environment. People are more curious about that beautiful distro rather than the awesome presentation I just did 😂</p><p>Not that I’m complaining, I love my desktop setup. I love it so much that I was afraid of getting a new PC when I was due for one. I was afraid that I would mess things up(I have done that many times in the past, I think Linux users can relate to me)</p><p>So I decided to capture the most important aspects of my distro for anyone interested in using Linux as their primary OS for development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*RHXewE9hsQ-2lu2X.png" /></figure><p>This is not just my work laptop, it’s my primary machine which I use for all of the below</p><ul><li>Java, JS, TS, Go, Python &amp; web development</li><li>JHipster development</li><li>Running multiple web applications locally</li><li>Running Docker containers</li><li>VirtualBox for Windows testing &amp; other VM stuff</li><li>Kubernetes, Terraform, CloudFormation development and deployments</li><li>Azure, AWS &amp; GCP deployments using required CLI tools</li><li>Heavy browser usage</li><li>Email, chat &amp; video conferencing</li><li>Plex media server</li><li>Blogging</li><li>Youtube &amp; Social media</li></ul><h3>Machine configuration</h3><p>The configuration of the machine is also quite important for any development setup. So my laptop is a Dell Precision 5530 Mobile Workstation. I had the exact same setup with my old Dell 5510 as well, which is quite a similar configuration to 5530. I still have it as a backup Laptop, its 2 years old now but can still give most of the top end laptops today a run for its money.</p><p>I used the <a href="https://www.dell.com/nl-nl/work/shop/isv-gecertificeerd-en-geoptimaliseerd-workstation/precision-5530/spd/precision-15-5530-laptop/xctop5530emea?selectionState=eyJGUHJpY2UiOjMwODcuNDUsIklVUHJpY2UiOjMwODcuNDUsIk9DIjoieGN0b3A1NTMwZW1lYSIsIlF0eSI6MSwiUHJTdCI6IiIsIk1vZHMiOlt7IklkIjoxNDYsIk9wdHMiOlt7IklkIjoiR0NCV1pVMiJ9XX0seyJJZCI6MTEsIk9wdHMiOlt7IklkIjoiR1JFUEZVMiJ9XX0seyJJZCI6MTQ5LCJPcHRzIjpbeyJJZCI6Ikc1R0FJQzgifV19LHsiSWQiOjYsIk9wdHMiOlt7IklkIjoiRzBTTVk1OSJ9XX0seyJJZCI6MywiT3B0cyI6W3siSWQiOiJHSk1TVDRLIn1dfSx7IklkIjo4LCJPcHRzIjpbeyJJZCI6IkdSMlNHSkgifV19LHsiSWQiOjM3MiwiT3B0cyI6W3siSWQiOiJHM1c1QzZIIn1dfSx7IklkIjoxMDAyLCJPcHRzIjpbeyJJZCI6IkdFODBUOVcifV19LHsiSWQiOjc0OSwiT3B0cyI6W3siSWQiOiJHOEJYV1lJIn1dfSx7IklkIjo1NSwiT3B0cyI6W3siSWQiOiJHSkVWUDNYIn1dfSx7IklkIjoxMTIsIk9wdHMiOlt7IklkIjoiR1c5SUs3RiJ9XX0seyJJZCI6MTAwMywiT3B0cyI6W3siSWQiOiJHNlE1WFo0In1dfSx7IklkIjoyMDAwNzYsIk9wdHMiOlt7IklkIjoiR1cyRVNBNyJ9XX0seyJJZCI6MzAsIk9wdHMiOlt7IklkIjoiODI3ODc1In1dfV19&amp;cartItemId=c4d9c6f5-9956-4c6f-87ac-d0472018ad78">custom configuration</a> option from Dell to get the best possible setup at that time. it’s not cheap but my company, <a href="https://xebialabs.com/">XebiaLabs</a>, provided a handsome budget and I think it is worth every penny. This, in my opinion, is one of the best Laptop for developers. So here is what I have.</p><p><strong>Processor</strong>: Intel® Core™ i9–8950HK CPU @ 2.90GHz × 12</p><p><strong>Memory</strong>: 32GB, DDR4–2666MHz SDRAM, 2 DIMMS, Non-ECC</p><p><strong>HDD</strong>: M.2 1TB NVMe PCIe SED class 40 SSD</p><p><strong>Graphics</strong>: NVIDIA Quadro P2000 with 4 GB GDDR5 memory &amp; Intel® UHD Graphics 630 (Coffeelake 3x8 GT2)</p><p><strong>Wireless</strong>: Intel Wifi Link 9260 2x2 802.11AC + BT 4.2 vPro wireless card</p><p><strong>Keyboard</strong>: English QWERTY US, backlit</p><p><strong>Display</strong>: 15.6&quot; FHD 1920x1080 Anti-Glare LED-backlit Non-touch IPS UltraSharp™</p><p><strong>Battery</strong>: 6-cell (97Wh) Lithium Ion battery with ExpressCharge™</p><h3>Operating system and desktop environment</h3><p>The most important of course is the operating system, I’m running <a href="https://getfedora.org/">Fedora 30</a> at the moment with <a href="https://www.gnome.org/">GNOME 3.32.2</a> as the Desktop and I’m very happy with it. I find Fedora more suitable for development machines than other distros as it has a short release cycle and is fairly stable so you get latest &amp; stable software all the time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/0*elvn2X88C-5WpybK.png" /></figure><p>What good is a desktop without a nice theme right? GNOME is great when it comes to themes and I went with <a href="https://github.com/andreisergiu98/arc-flatabulous-theme">Arc-Flatabulous</a> theme and never looked back. For icons, I use <a href="https://github.com/snwh/paper-icon-theme">Paper</a> as I like the material icon theme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*pvInABImQawwcjFM.png" /></figure><p>Of course, it won&#39;t be complete without some nice GNOME plugins. Below are the plugins that I use.</p><ul><li><a href="https://extensions.gnome.org/extension/307/dash-to-dock/">Dash to Dock</a></li><li><a href="https://extensions.gnome.org/extension/503/always-zoom-workspaces/">Always Zoom Workspaces</a></li><li><a href="https://extensions.gnome.org/extension/16/auto-move-windows/">Auto Move Windows</a></li><li><a href="https://extensions.gnome.org/extension/18/native-window-placement/">Native Window Placement</a></li><li><a href="https://extensions.gnome.org/extension/600/launch-new-instance/">Launch new instance</a></li><li><a href="https://extensions.gnome.org/extension/234/steal-my-focus/">Steal My Focus</a></li><li><a href="https://extensions.gnome.org/extension/15/alternatetab/">AlternateTab</a></li><li><a href="https://extensions.gnome.org/extension/602/window-list/">Window List</a></li><li><a href="https://extensions.gnome.org/extension/6/applications-menu/">Applications Menu</a></li><li><a href="https://extensions.gnome.org/extension/517/caffeine/">Caffeine</a></li><li><a href="https://extensions.gnome.org/extension/779/clipboard-indicator/">Clipboard Indicator</a></li><li><a href="https://extensions.gnome.org/extension/917/gistnotes/">Gistnotes</a></li><li><a href="https://extensions.gnome.org/extension/750/openweather/">OpenWeather</a></li><li><a href="https://extensions.gnome.org/extension/8/places-status-indicator/">Places Status Indicator</a></li><li><a href="https://extensions.gnome.org/extension/120/system-monitor/">System-monitor</a></li><li><a href="https://extensions.gnome.org/extension/570/todotxt/">Todo.txt</a></li><li><a href="https://extensions.gnome.org/extension/1031/topicons/">TopIcons Plus</a></li><li><a href="https://extensions.gnome.org/extension/19/user-themes/">User Themes</a></li></ul><h3>Development tools</h3><p>Now, these are mostly objective choices and really doesn’t matter as long as you are comfortable with the tools you choose. Below are my choices for some of the important categories for development. I’m not including obvious things like Vim, Git, NodeJS, Docker, Kubernetes, etc.</p><p><strong>Shell</strong>: This is one of the most important for a developer. I use <a href="https://www.zsh.org/">ZSH</a> along with the awesome <a href="https://ohmyz.sh/">Oh My ZSH</a> as my shell. Now, this won’t be complete without some nice plugins and theme. I use <a href="https://github.com/bhilburn/powerlevel9k">powerlevel9k</a> theme with some customizations. I also use <a href="https://github.com/zsh-users/zsh-autosuggestions">zsh-autosuggestions</a>, git, docker, docker-compose, autojump, <a href="https://github.com/zsh-users/zsh-syntax-highlighting">zsh-syntax-highlighting</a>, dnf, and npm plugins for Oh My ZSH. Here is my .zshrc with all the customizations. <strong>Update</strong>: A <a href="https://dev.to/java4africa/comment/c319">comment</a> on this post suggested <a href="https://github.com/romkatv/powerlevel10k">powerlevel10k</a> as an alternative theme and I tried it and turns out it is really way faster than powerlevel9k. So I think I&#39;m gonna use powerlevel10k as my shell theme.</p><p><strong>Terminal</strong>: What good is a nice shell without a good terminal. Fortunately, we have <a href="https://gnunn1.github.io/tilix-web/">Tilix</a> one of the best terminal application out there. It has workspaces, tabs, split windows, Quake mode and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*2aaWf8VIEFcoBYdg.png" /></figure><p><strong>Integrated development environment(IDE)</strong>: <a href="https://www.jetbrains.com/idea/">IntelliJ IDEA ultimate</a> — I use this only for Java &amp; other JVM language Development</p><p><strong>Code Editors</strong>: <a href="https://code.visualstudio.com/">Visual Studio Code</a> — My go-to editor. I love it. I use VSCode for web development, Go, Python, JS development, DevOps and everything other than JVM languages. A VSCode setup is never complete without some good plugins. <a href="https://gist.github.com/deepu105/4599d3b381218b9d1a63119fbf9ca537">Here</a> are the plugins that I’m using. You can run the script to install those.</p><p>Other notable development tools I use are <a href="https://www.gitkraken.com/">GitKraken</a> for Git repo management, <a href="https://www.scootersoftware.com/">Beyond Compare</a> for code comparisons, <a href="https://www.virtualbox.org/">VirtualBox</a>, <a href="https://github.com/nvm-sh/nvm">NVM</a> for NodeJS version management and <a href="https://sdkman.io/">SDKMan</a> for JDK version management.</p><h3>Productivity tools</h3><p>Productivity tools are also quite important and below are my choices.</p><p><strong>Browser</strong>: Google Chrome is my primary browser. I also use Firefox &amp; Opera sometimes. I do love Opera in terms of its UX, I would love to use it as my primary browser but I miss everything I have synchronized with my Google account in Chrome.</p><p><strong>Email</strong>: I use <a href="https://getmailspring.com/">Mailspring</a> as my e-mail client. Its a fairly decent mail client with nice themes and a simple UI.</p><p><strong>Office suite</strong>: I mostly use Google Docs &amp; Microsoft office online but when I have to work on something on my Desktop I use <a href="https://www.libreoffice.org/">LibreOffice</a> which is a good office suite and even handles Microsoft Office &amp; Keynote formats.</p><p><strong>Communication</strong>: Of course I use <a href="https://slack.com/">Slack</a> and for video conference I use <a href="https://www.bluejeans.com/">BlueJeans</a>.</p><p><strong>Screen capture</strong>: I use this nifty tool called <a href="https://github.com/phw/peek">Peek</a> for screen recording and <a href="https://launchpad.net/shutter">Shutter</a> for screenshots.</p><h3>Conclusion</h3><p>There are many other small and nifty utilities that I use, most are command line utilities. There are some notable mentions like <a href="https://github.com/teejee2008/timeshift">Timeshift</a> which is nice for backing up your machine.</p><p>Of course, not everything is perfect in the Linux world, but it is the same with every OS. I was a long time Windows user before switching to Linux. So like every Linux users I have from time to time messed things up(With great power comes great responsibility, Peter). There are many quirks in the Linux world but there is nothing that bothers me much. Some of the most annoying issues I had in the past are below and for now, I don’t have any noticeable issues.</p><ul><li>Scroll position jumping when switching apps — Fixed after upgrading to Fedora 30</li><li>Hibernation was broken — Fixed after upgrading to Fedora 30</li><li>Audio output selection was broken when plugging in headphones- Fixed after Fedora 28 for me</li></ul><h3>𝔻𝕖𝕖𝕡𝕦 𝕂 𝕊𝕒𝕤𝕚𝕕𝕙𝕒𝕣𝕒𝕟 on Twitter</h3><p>This has been a good day, upgraded to #Fedora 30 and hibernate started to work again. Sweet. I was putting off tinkering that for a long time. #Linux</p><p>I hope you find this useful. If you have any question or if you think I missed something please add a comment.</p><p>If you like this article, please leave a like or a comment.</p><p>You can follow me on <a href="https://twitter.com/deepu105">Twitter</a> and <a href="https://www.linkedin.com/in/deepu05/">LinkedIn</a>.</p><p><em>Originally published at </em><a href="https://dev.to/deepu105/my-beautiful-linux-development-environment-2afc"><em>https://dev.to</em></a><em> on June 16, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d96d4e4e2f62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I’m moving away from Medium]]></title>
            <link>https://medium.com/@deepu105/why-im-moving-away-from-medium-f9153a01247e?source=rss-28fde566f680------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9153a01247e</guid>
            <category><![CDATA[blogging]]></category>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[dev]]></category>
            <dc:creator><![CDATA[Deepu K Sasidharan]]></dc:creator>
            <pubDate>Wed, 12 Jun 2019 22:06:01 GMT</pubDate>
            <atom:updated>2019-06-21T08:49:32.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dgklwR8UeGO3gZKEnMBcgA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@milkovi?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">MILKOVÍ</a> on <a href="https://unsplash.com/search/photos/writing?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>After much deliberation, I have decided to move my blogs away from Medium. I was considering setting up my own blog with <a href="https://gohugo.io/">Hugo</a> but then decided to go with <a href="https://dev.to/deepu105">Dev.to</a>. Below are the reasons why I decided to leave Medium and why I chose Dev.to.</p><p>All considerations were purely from a technical writing perspective as I was using Medium for publishing technical content.</p><h4>The love-hate relationship with Medium</h4><p>I loved Medium when I started writing here, reasons being;</p><ul><li>A simple minimal &amp; clean UI — It still is one of the best</li><li>Ease of authoring and publishing</li><li>Community and visibility</li><li>Publications</li><li>Ease of customization</li></ul><p>But there were also things I didn’t like much which slowly become quite annoying</p><ul><li>The weird commenting mechanism(Every comment is a post, and they literally mess up your stories listing page)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nnAeUa07rTwcFw-iMBe1vQ.png" /></figure><ul><li>Medium had a weird WYSIWYG editor interface which is great for normal content creation but not so great for technical content creation. It had some markdown like shortcuts, but it could never match the ease of using proper markdown editors.</li><li>Export only in HTML (Duh!!)</li></ul><p>But these annoyances were not the main reason I decided to switch platforms. Below are the main reasons why I decided Medium isn’t a good fit for me.</p><p>Medium has been aggressively pushing for content to be put behind a paywall and they have made it clear that content not opting in will not get any push inside the platform. This means the community and visibility part is applicable only if you opt-in for the paywall. I understand why Medium does and I think its a great monetary source for established authors but it doesn’t work for mere mortals like me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*yq7VjalsUx_ujXWeEKpAag.png" /></figure><p>As a result of the above, the traffic you get from Medium itself is very low compared to external sources. See one of my stories below for an example. For newer stories, it is even lower.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*buR4q7oynmBkYmHGLx_jtw.png" /></figure><p>So writing in Medium seems to have no benefit over other platforms as I could get similar views from external sources and might get better writing experience elsewhere.</p><p><strong>Update</strong></p><p>So after a week of moving to the Dev community below are my stats and its incredible, I have ~50k views, ~1k reactions and ~300 followers and one of my post were <a href="https://dev.to/devteam/the-7-most-popular-dev-posts-from-the-past-week-5ahf">featured in top 7</a> of the week and all this in just 1 week. I didn’t get anything remotely close to this from Medium in a year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*J1ZnpDVQ-ih0JVvaOpjg-A.png" /></figure><h4>Enter Dev.to</h4><p>When I was trying to find a different platform, some of the most important aspects I considered were below</p><ul><li><strong>Community</strong>: A community without paywall and a community were your blogs get visibility and get traffic.</li><li><strong>Ease of authoring</strong>: Authoring experience was important, hence at minimum Markdown support was a must. This way I can author posts in my favorite IDE(VsCode in this case) and doesn’t have to be restricted with the platform&#39;s capability. Also, this ensures that I can easily move my posts to another platform in the future if needed.</li></ul><p>Dev.to satisfied these needs and provided a nice and clean UI and descent publishing experience on top.</p><h4><strong>Conclusion</strong></h4><p>I think Medium is still perfect for normal blogging and for content creators who have subscribers willing to pay even if they put articles behind a paywall. But for technical content creators who do not want their content behind a paywall, there are better platforms. I might still crosspost between Dev.to and Medium from time to time but Dev.to will be my primary blogging platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9153a01247e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Continuous delivery of Microservices with XebiaLabs — a.k.a DevOps as Code]]></title>
            <link>https://medium.com/xebialabs/continuous-delivery-of-microservices-with-xebialabs-a-k-a-devops-as-code-b5f0c3b2b1c8?source=rss-28fde566f680------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5f0c3b2b1c8</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[jhipster]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Deepu K Sasidharan]]></dc:creator>
            <pubDate>Tue, 02 Apr 2019 15:30:16 GMT</pubDate>
            <atom:updated>2019-04-03T16:01:46.516Z</atom:updated>
            <content:encoded><![CDATA[<h3>Continuous delivery of Microservices with XebiaLabs — a.k.a DevOps as Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qcwbVbdTCeduF24q3G1Tsw.png" /></figure><p>Are you on the DevOps bandwagon yet? If not it&#39;s a great time to get on board. You would have heard the terminology at least once in your career and if you are wondering what it really means then let me tell you, it&#39;s all about <strong>CI/CD </strong>(continuous integration or continuous delivery) of your application, at least that is what matters the most, everything else is just noise.</p><p>Are you a developer who is annoyed with all the different tools and processes that are needed to set up your CI/CD setup, struggling with GUI tools and drowning in custom scripts and endless Jenkins Jobs? Then this post is for you. Are you a DevOps engineer who is more comfortable with a declarative approach to DevOps? Then this post is also for you. Are you an enterprise developer/architect looking for a right CI/CD setup that complies to your organization&#39;s compliance standards and security requirements? Then this post is for you as well.</p><p>Proper Continuous Integration and delivery setup can do great wonders for your application and your team, especially when you are doing complex microservice architectures. Manual deployments and the delivery cycle just can&#39;t cut it anymore. Imagine having a Kubernetes cluster with hundreds of microservices (or even a handful for that matter) and having to rollback them manually when one of the dependent services fail.</p><p>If you have been following my <a href="https://medium.com/@deepu105">blog</a> you would have noticed that I’m writing a lot about Microservices, Kubernetes, and JHipster and since I work for a great DevOps company, it&#39;s time that I combine all these into a blog post focusing on DevOps for microservices. So, today we will create a full-fledged microservice stack using JHipster and then deploy it to Google Kubernetes Engine. The Google Cloud Platform (GCP) infrastructure will be provisioned using Terraform. All this will be orchestrated using the XebiaLabs DevOps Platform and we will scaffold the provisioning scripts, deployment manifest, and release manifest using XebiaLabs Command line tool (XL CLI). We will also be using Jenkins as our CI tool.</p><h4>Why XebiaLabs</h4><p>XebiaLabs is a leading provider of enterprise DevOps software. The XebiaLabs DevOps Platform includes <strong>XL Deploy</strong> for deployment automation and <strong>XL Release</strong> for release orchestration, along with few other products focusing on DevOps intelligence and analytics. You can learn more about specific products and offerings <a href="https://xebialabs.com/products/">here</a>.</p><p>So why XebiaLabs? XebiaLabs has one of the most sophisticated release orchestration and deployment automation tools that I have seen, I’m not saying it because I work for XebiaLabs, I’m saying it as a developer who has some exposure to DevOps tools and who has done his fair share of DevOps. The XebiaLabs DevOps Platform is really powerful, especially when it comes to complex enterprise applications with a lot of processes, compliance, and security requirements. It may not be groundbreaking for small applications but you really start seeing the benefit as soon as you start adding complex steps into your CI/CD process. On top of that, it provides useful features like reporting, a nice and interactive UI and so on.</p><p>Now for the techies (like me), who would like even their wedding invitation probably to be in code, XebiaLabs also provides something we call <strong>DevOps as Code</strong>, a comprehensive YAML-based schema for defining deployments and release process as declarative code, and a nice CLI along with starter templates a.k.a <strong>blueprints</strong>. We shall see more about this later.</p><p>For this demo, we will be using both XL Release and XL Deploy along with the DevOps as Code features.</p><h4>Why JHipster</h4><p>If you have been following my blog then JHipster needs no introduction. JHipster is the leading rapid application development platform for the JVM ecosystem. It can help you to create monolith and microservice web applications with Spring Boot and Angular/React/VueJS in minutes. You can learn more about JHipster <a href="https://www.jhipster.tech/">here</a>. JHipster also provides a nice DSL to define our applications, entities, and deployment options. Check out my previous <a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">post</a> about creating microservices with JHipster for more details.</p><p>We will be using JHipster to scaffold our microservice applications.</p><h4>Why Terraform</h4><blockquote>HashiCorp Terraform enables you to safely and predictably create, change, and improve infrastructure. It is an open source tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.</blockquote><p>Terraform offers what is commonly known as Infrastructure-as-Code. It is a powerful tool with a nice CLI to provision and teardown infrastructure in a variety of cloud and native environments. It&#39;s a truly cross-platform provisioning solution and best of its breed.</p><p>We will use Terraform to provision our <strong>Google Cloud</strong> infrastructure.</p><h3>XebiaLabs DevOps as Code</h3><p>Now that the introductions are done let us take a closer look at the XebiaLabs DevOps as Code.</p><p>The DevOps as Code offering is made of three main components — Blueprints, XL YAML files, and XL CLI.</p><p><a href="https://docs.xebialabs.com/xl-platform/concept/get-started-with-blueprints.html">Blueprints</a> are templates written using our in-house scaffolding mechanism built on top of Go templating language. We use blueprints to provide starter templates for the DevOps as Code feature. Blueprints are quite similar to JHipster as it helps to scaffold configurations for provisioning and DevOps so that you can focus on getting work done rather than writing boilerplate code.</p><p>The <a href="https://docs.xebialabs.com/xl-platform/how-to/work-with-xl-yaml-format.html">XL YAML files</a> provide a comprehensive schema to define release pipelines for XL Release and deployment configurations for XL Deploy. It can be used to completely replace the UI based configurations of both the products. This lets us iterate faster and have a more natural way of defining our DevOps pipeline right from our favorite IDE/Editor</p><p>Finally, the <a href="https://docs.xebialabs.com/xl-platform/concept/xl-cli-command-reference.html">XL CLI</a> helps to put everything together, soit can be used to run blueprints and to apply the XL YAML files to the respective products and more.</p><h3>Prerequisites</h3><p>Before we start you would need to set up a few tools in order to proceed.</p><p>First, you would need to install JHipster if you haven&#39;t already. Follow the official instructions <a href="https://www.jhipster.tech/installation/">here</a> to set it up.</p><p>Second, let us install XL CLI using the official instructions <a href="https://docs.xebialabs.com/xl-platform/how-to/install-the-xl-cli.html">here</a>. Use the 8.6.1 version.</p><h3>Creating the microservice stack using JHipster</h3><p>Now let us create our microservice applications. We will be using JDL (JHipster Domain Language) to model our applications.</p><p>In one of my <a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">previous posts</a>, I showcased how to create a full stack microservice architecture using <strong>JHipster</strong> and <strong>JDL. </strong>Read the post <a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">here</a> if you want to learn more details about it. For this exercise, we will use the same application.</p><p>Let us take a quick look at the application architecture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*mn5RFxACkpKoojSoMNYi9w.png" /><figcaption>Microservice application architecture</figcaption></figure><p>Let us recap the steps required.</p><p>Create a JDL file, let’s say <strong><em>app.jdl</em></strong>, and copy the below content into it.</p><pre>application {<br>  config {<br>    baseName store,<br>    applicationType gateway,<br>    packageName com.jhipster.demo.store,<br>    serviceDiscoveryType eureka,<br>    authenticationType jwt,<br>    prodDatabaseType mysql,<br>    cacheProvider hazelcast,<br>    buildTool gradle,<br>    clientFramework react,<br>    useSass true,<br>    testFrameworks [protractor]<br>  }<br>  entities *<br>}</pre><pre>application {<br>  config {<br>    baseName invoice,<br>    applicationType microservice,<br>    packageName com.jhipster.demo.invoice,<br>    serviceDiscoveryType eureka,<br>    authenticationType jwt,<br>    prodDatabaseType mysql,<br>    buildTool gradle,<br>    serverPort 8081,<br>    skipUserManagement true<br>  }<br>  entities Invoice, Shipment<br>}</pre><pre>application {<br>  config {<br>    baseName notification,<br>    applicationType microservice,<br>    packageName com.jhipster.demo.notification,<br>    serviceDiscoveryType eureka,<br>    authenticationType jwt,<br>    databaseType mongodb,<br>    prodDatabaseType mongodb,<br>    devDatabaseType mongodb,<br>    cacheProvider no,<br>    enableHibernateCache false,<br>    buildTool gradle,<br>    serverPort 8082,<br>    skipUserManagement true<br>  }<br>  entities Notification<br>}</pre><pre>/* Entities for Store Gateway */</pre><pre>/** Product sold by the Online store */<br>entity Product {<br>    name String required<br>    description String<br>    price BigDecimal required min(0)<br>    size Size required<br>    image ImageBlob<br>}</pre><pre>enum Size {<br>    S, M, L, XL, XXL<br>}</pre><pre>entity ProductCategory {<br>    name String required<br>    description String<br>}</pre><pre>entity Customer {<br>    firstName String required<br>    lastName String required<br>    gender Gender required<br>    email String required pattern(/^[^@\s]+@[^@\s]+\.[^@\s]+$/)<br>    phone String required<br>    addressLine1 String required<br>    addressLine2 String<br>    city String required<br>    country String required<br>}</pre><pre>enum Gender {<br>    MALE, FEMALE, OTHER<br>}</pre><pre>entity ProductOrder {<br>    placedDate Instant required<br>    status OrderStatus required<br>    code String required<br>    invoiceId Long<br>}</pre><pre>enum OrderStatus {<br>    COMPLETED, PENDING, CANCELLED<br>}</pre><pre>entity OrderItem {<br>    quantity Integer required min(0)<br>    totalPrice BigDecimal required min(0)<br>    status OrderItemStatus required<br>}</pre><pre>enum OrderItemStatus {<br>    AVAILABLE, OUT_OF_STOCK, BACK_ORDER<br>}</pre><pre>relationship OneToOne {<br>    Customer{user(login) required} to User<br>}</pre><pre>relationship ManyToOne {<br> OrderItem{product(name) required} to Product<br>}</pre><pre>relationship OneToMany {<br>   Customer{order} to ProductOrder{customer(email) required},<br>   ProductOrder{orderItem} to OrderItem{order(code) required} ,<br>   ProductCategory{product} to Product{productCategory(name)}<br>}</pre><pre>service Product, ProductCategory, Customer, ProductOrder, OrderItem with serviceClass<br>paginate Product, Customer, ProductOrder, OrderItem with pagination</pre><pre>/* Entities for Invoice microservice */<br>entity Invoice {<br>    code String required<br>    date Instant required<br>    details String<br>    status InvoiceStatus required<br>    paymentMethod PaymentMethod required<br>    paymentDate Instant required<br>    paymentAmount BigDecimal required<br>}</pre><pre>enum InvoiceStatus {<br>    PAID, ISSUED, CANCELLED<br>}</pre><pre>entity Shipment {<br>    trackingCode String<br>    date Instant required<br>    details String<br>}</pre><pre>enum PaymentMethod {<br>    CREDIT_CARD, CASH_ON_DELIVERY, PAYPAL<br>}</pre><pre>relationship OneToMany {<br>    Invoice{shipment} to Shipment{invoice(code) required}<br>}</pre><pre>service Invoice, Shipment with serviceClass<br>paginate Invoice, Shipment with pagination<br>microservice Invoice, Shipment with invoice</pre><pre>/* Entities for notification microservice */</pre><pre>entity Notification {<br>    date Instant required<br>    details String<br>    sentDate Instant required<br>    format NotificationType required<br>    userId Long required<br>    productId Long required<br>}</pre><pre>enum NotificationType {<br>    EMAIL, SMS, PARCEL<br>}</pre><pre>microservice Notification with notification</pre><p>Now let us also add the Kubernetes deployment description to the JDL so we can generate Kubernetes manifests for all our applications as well. Make sure to use your own <strong><em>dockerRepositoryName</em></strong></p><pre>deployment {<br>  deploymentType kubernetes<br>  appsFolders [store, invoice, notification]<br>  <strong>dockerRepositoryName</strong> &quot;<strong>deepu105</strong>&quot;<br>  kubernetesNamespace xl-demo<br>}</pre><p>Now create a directory called <strong><em>ecommerce</em></strong> in your preferred location in the file system and navigate into it. Save the above JDL as <strong><em>app.jdl</em></strong> in the directory. Run the JHipster import-jdl command. It could take a few minutes, especially the NPM install step.</p><pre>$ mkdir ecommerce &amp;&amp; cd ecommerce<br>$ jhipster import-jdl app.jdl --skip-git</pre><p>Once the JHipster process is complete, you will see that we have our store gateway, invoice service and notification service created and ready for us. We also have the Kubernetes manifests created alongside.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*Mf2_-AVEWIlzKA3EMhUnDg.png" /><figcaption>Microservice folder structure</figcaption></figure><p>The process until this is explained in more detail in my previous post <a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">here</a> and you can deploy the application locally using Docker. If you haven’t done that before I strongly suggest that step so that you get an idea of the application and you also can make sure it works locally on your machine.</p><p>Now that our application is ready, let us set up a Jenkins CI build for the applications. In the spirit of true microservice, we will add a Jenkins job to each of the services.</p><p>Navigate into each of the <strong><em>store</em></strong>, <strong><em>invoice</em></strong> and <strong><em>notification</em></strong> folders and run the jhipster ci-cd command and follow the instructions. Choose the answers below for all the services. Use your own docker login name for “<strong><em>Organization Name for the Docker registry</em></strong>”.</p><pre>$ cd store</pre><pre>$ jhipster ci-cd<br>           <br>🚀 Welcome to the JHipster CI/CD Sub-Generator 🚀<br>? What CI/CD pipeline do you want to generate? <strong>Jenkins pipeline</strong><br>? Would you like to perform the build in a Docker container ? <strong>No</strong><br>? Would you like to send build status to GitLab ? <strong>No</strong><br>? What tasks/integrations do you want to include ? <strong>Build and publish a *Docker* image</strong><br>? *Docker*: what is the URL of the Docker registry ? <a href="https://registry.hub.docker.com/"><strong>https://registry.hub.docker.com</strong></a><br>? *Docker*: what is the Jenkins Credentials ID for the Docker registry ? <strong>docker-login</strong><br>? *Docker*: what is the Organization Name for the Docker registry ? <strong>deepu105</strong><br>   create Jenkinsfile<br>   create src/main/docker/jenkins.yml<br>   create src/main/resources/idea.gdsl<br>   create src/main/docker/docker-registry.yml<br>INFO! Congratulations, JHipster execution is complete!</pre><p>JHipster expects each project to live in its own Git repository, but for this demo, we will follow a <strong>monorepo</strong> approach, hence we need to adjust the generated <strong><em>Jenkinsfile</em></strong> to work with this. The change is simple, in each of the generated <strong><em>Jenkinsfile</em></strong>, we need to do a cd command before any command execution and adjust paths in copy commands. For example, below is the modified <strong><em>Jenkinsfile</em></strong> for store service with changes highlighted. Some unrelated code is truncated for brevity.</p><pre>...</pre><pre>node {<br>    ...</pre><pre>stage(&#39;clean&#39;) {<br>        sh &quot;<strong>cd store &amp;&amp;</strong> chmod +x gradlew&quot;<br>        sh &quot;<strong>cd store &amp;&amp;</strong> ./gradlew clean --no-daemon&quot;<br>    }</pre><pre>stage(&#39;npm install&#39;) {<br>        sh &quot;<strong>cd store &amp;&amp; </strong>./gradlew npm_install ...&quot;<br>    }</pre><pre>stage(&#39;backend tests&#39;) {<br>        try {<br>            sh &quot;<strong>cd store &amp;&amp;</strong> ./gradlew test ...&quot;<br>        } ...<br>    }</pre><pre>stage(&#39;frontend tests&#39;) {<br>        try {<br>            sh &quot;<strong>cd store &amp;&amp;</strong> ./gradlew npm_run_test-ci ...&quot;<br>        } ...<br>    }</pre><pre>stage(&#39;packaging&#39;) {<br>        sh &quot;<strong>cd store &amp;&amp; </strong>./gradlew bootWar ...&quot;<br>        ...<br>    }</pre><pre>def dockerImage<br>    stage(&#39;build docker&#39;) {<br>        sh &quot;cp -R <strong>store/</strong>src/main/docker <strong>store/</strong>build/&quot;<br>        sh &quot;cp <strong>store/</strong>build/libs/*.war <strong>store/</strong>build/docker/&quot;<br>        dockerImage = docker.build(&#39;docker-login/store&#39;, &#39;<strong>store/</strong>build/docker&#39;)<br>    }</pre><pre>...<br>}</pre><h3>Creating the CI/CD pipeline with XebiaLabs Blueprints</h3><p>Now that our application is ready, let us set up a CI/CD pipeline for the applications. We will use the XebiaLabs blueprint feature to scaffold this. At the root of our applications, that is the <strong><em>ecommerce</em></strong> directory, run the following command</p><pre>$ xl blueprint -b gcp/microservice-ecommerce</pre><p>This will prompt you with a bunch of questions. Each answer as highlighted below - for most of them you can use the default values provided.</p><pre>? What is the name of the application? <strong>e-commerce-ms</strong><br>? What is the GCP project ID? <strong>e-commerce-devops-playground</strong><br>? What is the username for Kubernetes cluster? <strong>admin</strong><br>? What is the password for Kubernetes cluster? (minimum 16 characters) *************************<br>? Select the GCP region: <strong>europe-west1</strong><br>? Do you want to provision a new GCP GKE cluster? <strong>Yes</strong><br>? What is the name of the cluster? <strong>e-commerce-ms</strong><br>? What is the name of the namespace? This should be same as the one used in Kubernetes files. <strong>xl-demo</strong><br>? Do you want to enable CI/CD integration with Jenkins? <strong>Yes</strong><br>? XL Deploy URL for XL Release (This will only be used in the XL Release template) <a href="http://xl-deploy:4516/"><strong>http://xl-deploy:4516</strong></a><br>? Confirm to generate blueprint files? <strong>Yes</strong></pre><p><strong>Note</strong>: If you have an existing Google Project ID you can use that and select a GCP region that is best suited for you. If you do not have a project yet create one through the Google Cloud GUI or using the command below.</p><pre>$ gcloud projects create <strong>e-commerce-devops-playground</strong> \<br> — organization [YOUR_ORG_ID] \<br> — set-as-default</pre><pre>$gcloud beta billing projects link <strong>e-commerce-devops-playground</strong> \<br> — billing-account [YOUR_BILLING_ACCOUNT_ID]</pre><p>The value of <strong><em>YOUR_ORG_ID</em></strong> and <strong><em>YOUR_BILLING_ACCOUNT_ID</em></strong> can be found by running below commands</p><pre>$ gcloud organizations list<br>$ gcloud beta billing accounts list</pre><p>This will generate the XebiaLabs YAML files under the <strong><em>xebialabs</em></strong> folder and Terraform provisioning scripts under a <strong><em>terraform</em></strong> folder and a docker-compose file under the <strong><em>docker</em></strong> folder. It will also create a <strong><em>xebialabs.yaml</em></strong> file at the root for the convenience of execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*cHBQN4-6TdC4j7hMChyp-w.png" /><figcaption>Folder structure with DevOps as Code</figcaption></figure><h4>DevOps as Code</h4><p>Let&#39;s have a quick look at the XebiaLabs YAML files generated.</p><p><strong><em>xld-infra-env.yaml</em></strong>: This defines the GCP infrastructure and environment to be used by XL Deploy to provision the terraform infrastructure and to deploy our application</p><p><strong><em>xld-kubernetes-*-app.yaml</em></strong>: These files define the XL Deploy deployment packages for each of our microservice applications.</p><p><strong><em>xld-terraform-apps.yaml</em></strong>: This file defines the XL Deploy deployment packages for the Terraform provisioning scripts that creates our Kubernetes cluster and the namespace</p><p><strong><em>xlr-pipeline-ci-cd.yaml</em></strong>: This file defines the entire provisioning and release orchestration pipeline for XL Release. You could also use separate XL Release pipelines for provisioning and release if you like. XL Release will skip the provisioning steps if the infrastructure doesn&#39;t have any changes.</p><p><strong><em>xlr-pipeline-destroy.yaml</em></strong>: This file defines a pipeline to de-provision and un-deploy everything. This is kind of a cleanup pipeline.</p><h4>Infrastructure as code using Terraform</h4><p>We also generated some Terraform scripts to provision our infrastructure:</p><p><strong><em>gke</em></strong>: This module defines the GKE cluster.</p><p><strong><em>vpc</em></strong>: This module defines the VPC, Subnets, and Firewall rules for the cluster.</p><p><strong><em>main.tf</em></strong>: The main module ties everything together.</p><p><strong><em>backend.tf</em></strong>: The backend module defines a Google Cloud Storage backend to store the Terraform state.</p><h3>Deploying to Google Cloud Platform using XL Release CI/CD pipeline</h3><p>Now, let&#39;s start our CI/CD journey.</p><h4>Google Cloud Environment preparation</h4><p>Before we jump in we need to set up a Google Cloud project. Detailed steps to do this are described in the <strong>Prerequisites</strong> section of <strong><em>xebialabs/USAGE.md</em></strong> which is generated along with the blueprint in the previous step.</p><p>Make sure you have the <a href="https://cloud.google.com/sdk/gcloud/">gcloud CLI</a> setup and authenticated and then refer the <strong><em>xebialabs/USAGE.md</em> </strong>file to set up the Google Cloud Project, a service account, and the back-end storage to store the tfstate file in Cloud Storage.</p><p>You would have downloaded an <strong><em>account.json</em></strong> file from this step, copy that into the <strong><em>terraform</em></strong> folder that was generated when you executed the blueprint in the previous step.</p><h4>Setting up XL Release, XL Deploy, and Jenkins with Docker</h4><p>We would also need to run an instance of XL Release, XL Deploy, Jenkins and Terraform, let us use the preconfigured docker-compose file generated by the blueprint to quickly run these tools.</p><p>Navigate to the <strong><em>docker</em></strong> folder generated by the blueprint</p><pre>$ cd ecommerce/docker</pre><p>Before we start the containers we need to specify a few environment variables for our Jenkins setup as below</p><pre>$ export GITHUB_USER=&lt;your GitHub user name&gt;<br>$ export DOCKER_USER=&lt;your Docker user name&gt;<br>$ export DOCKER_PASS=&lt;your Docker password&gt;</pre><p>We also need to ensure that Jenkins can build our applications. In the provided docker-compose setup there are preconfigured Jenkins jobs that will build the application. It looks for a GitHub repository <strong>https://github.com/${GITHUB_USER}/e-commerce-microservice.git</strong> with a <strong>gke-blueprint</strong> branch to check out the application. So please create the <strong>e-commerce-microservice</strong> repository under your GitHub user and commit everything we generated so far and push it to that repository. If you can’t use that name then update the generated <strong><em>docker/jenkins/jenkins.yaml</em></strong> file to reflect the new repository/branch name you want to use. Follow the below steps to init and push to the Git repository.</p><pre>$ cd ecommerce<br>$ git init<br>$ git remote add <strong>upstream</strong> <a href="https://github.com/deepu105/e-commerce-microservice.git">https://github.com/</a><strong>$GITHUB_USER</strong><a href="https://github.com/deepu105/e-commerce-microservice.git">/e-commerce-microservice.git</a><br>$ git add --all<br>$ git commit -am &quot;your message here&quot;<br>$ git checkout -b <strong>gke-blueprint</strong><br>$ git push <strong>upstream</strong> <strong>gke-blueprint</strong></pre><p>Now we can start the Docker containers by running the below command.</p><pre>$ docker-compose up -d</pre><p>This will spin up all our containers in daemon mode so that we don’t accidentally kill them by <strong><em>ctrl+c</em></strong></p><p>Visit the following URLs to ensure all the services are running correctly, you should be able to see the UI for the services. It could take a few minutes for all services to be up and running.</p><p><strong>XL Release</strong><em>: </em><a href="/service/localhost:5516"><em>localhost:5516</em></a></p><p><strong>XL Deploy</strong><em>: </em><a href="/service/localhost:4516"><em>localhost:4516</em></a></p><p><strong>Jenkins</strong><em>: </em><a href="/service/localhost:8080"><em>localhost:8080</em></a></p><p>Note: The username and password is “<strong><em>admin</em>”</strong> for all the above services. You can change them in the docker-compose files if you like.</p><h4>Applying the XebiaLabs DevOps as Code YAML</h4><p>Now that everything is ready, let’s use the generated XL YAML files. Apply them using the below command from the project root.</p><pre>$ xl apply -f xebialabs.yaml</pre><p>This will apply all the XL Release and XL Deploy configurations and will print out information regarding what was done.</p><h4>XL Deploy deployments</h4><p>Let us take a look at what was created in XL Deploy. Log in and visit the <a href="http://localhost:4516/#/explorer"><strong><em>explorer</em></strong> tab</a> in XL Deploy. Expand the entries in <strong><em>Applications</em></strong>, <strong><em>Environments</em></strong>, and <strong><em>Infrastructure</em></strong> and play around to see how the Terraform and Kubernetes deployments are mapped. Visit the <a href="https://docs.xebialabs.com/xl-deploy/">XL Deploy documentation</a> to understand the concepts and the GUI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q7OrMK6lGVsgURzG5XpdCw.png" /><figcaption>XL Deploy configuration items in explorer GUI</figcaption></figure><h4>XL Release pipeline</h4><p>Let us take a look at what was created in XL Release. Log in and visit the <a href="http://localhost:5516/#/folders"><strong><em>design</em></strong> tab</a> in XL Release and click on the “<strong><em>e-commerce-ms”</em> </strong>folder (The name will be different if you used a different name during blueprint generation). Now click on “<strong><em>e-commerce-ms-ci-cd”</em> </strong>from the list to see the pipeline template. Visit the <a href="https://docs.xebialabs.com/xl-release/">XL Release documentation</a> to understand the concepts and the GUI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*24YRYjcLWHMOn6qIAB7iJA.png" /><figcaption>XL Release pipeline template</figcaption></figure><p><strong>Running the Release pipeline</strong></p><p>Let us go ahead and run our release. In the XL Release pipeline template that we saw earlier, click on the “<strong><em>new release”</em></strong> button. Fill in a name for the release and click “<strong><em>create”</em></strong><em>.</em><strong><em> </em></strong>In the resulting pipeline click “<strong><em>start release” </em></strong>and then “<strong><em>start”</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfF8fzMRwmhH3HIdKlQi5g.png" /><figcaption>Running release from XL Release pipeline</figcaption></figure><p>The release will start provisioning a GKE cluster first and then will build our applications using Jenkins which will build and push docker images to docker registry. XL Release will then orchestrate the Kubernetes deployment to the cluster that we created to do a smoke test and present the URL for you to verify. You can click on each task to see more details and to see log outputs. The release should take approximately 15 to 20 minutes when everything goes well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PZGZc7wj4yXcQE9NZxYaA.png" /><figcaption>Release with the final confirmation step</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YAtzpgRzokfoc1ag2Xhcpw.png" /><figcaption>Confirmation step</figcaption></figure><h4>Microservice Gateway</h4><p>When you click on the URL presented after the release you should see the dapper looking guy below greeting you. Explore application and play with different services. You can mark the final task of the release as complete once you verify everything. This will complete the release.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P-kZyDzJmMyRa8b-qjPbhA.png" /><figcaption>Microservice gateway application</figcaption></figure><h4>Google Cloud Console</h4><p>Let us take a look at the Google Cloud Console to see our GKE cluster. Let us look at the node and workloads respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_GpxN3MH8gNMdhtfZQKcw.png" /><figcaption>Google Kubernetes Engine nodes</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*8snGo64lS9TtlE88iFnm4w.png" /><figcaption>Google Kubernetes Engine workloads</figcaption></figure><p>We can see that all the services are deployed and are running successfully.</p><h4>Teardown and de-provisioning with XL Release</h4><p>The blueprint also generated a handy teardown template so that we can undeploy and deprovision everything we created. You can visit the <a href="http://localhost:5516/#/folders"><strong><em>design</em></strong> tab</a> in XL Release and click on the “<strong><em>e-commerce-ms”</em> </strong>folder. Now click on “<strong><em>e-commerce-ms-destroy”</em> </strong>from the list to see the pipeline template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jz3Qs0o8GhoS9xudX-RWxg.png" /><figcaption>XL Release template for teardown</figcaption></figure><p>This template will undeploy the applications with Kubernetes and will deprovision the GKE infrastructure with Terraform. To run this, click on the “<strong><em>new release”</em></strong> button. Fill in a name for the release and click “<strong><em>create”</em></strong><em>.</em><strong><em> </em></strong>In the resulting pipeline click “<strong><em>start release” </em></strong>and then “<strong><em>start”</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNMpt7WnPtfc6HXMJKGuzA.png" /><figcaption>Completed release for teardown</figcaption></figure><h3>Conclusion</h3><p>Microservices are not easy, DevOps for microservices makes it even harder and simple orchestration tools fall short when it comes to orchestrating complex microservice deployment pipelines. Of course, we can write our own orchestration scripts using any script runner like Jenkins, but it doesn&#39;t scale when it comes to bigger teams and especially enterprises. This is where the XebiaLabs DevOps Platform shines as it provides all those annoying bits and pieces like process, quality and security assurances, which is not the fun part of DevOps. As I highlighted earlier, if you have simple apps then this may not be for you. But if you are in a process-oriented team which has to care about security, quality, and all the other boring stuff that big companies and enterprises care about, then you might need something like this.</p><p>You can learn all about XebiaLabs on the official website <a href="https://xebialabs.com/">here</a> and the product docs <a href="https://docs.xebialabs.com/">here</a>.</p><p>JHipster provides a great platform for microservice development. To learn more about JHipster and Full stack development, check out my book “<em>Full Stack Development with JHipster</em>” on <a href="https://www.amazon.com/Stack-Development-JHipster-Deepu-Sasidharan/dp/178847631X">Amazon</a> and <a href="https://www.packtpub.com/application-development/full-stack-development-jhipster">Packt</a>.</p><p>If you like JHipster don’t forget to give it a star on <a href="https://github.com/jhipster/generator-jhipster">Github</a>.</p><p>If you like this article, please leave some claps (Did you know that you can clap multiple times in Medium? 😁) I hope to write more about microservices and DevOps in the near future.</p><p>You can follow me on <a href="https://twitter.com/deepu105">Twitter</a> and <a href="https://www.linkedin.com/in/deepu05/">LinkedIn</a>.</p><p>My other related posts:</p><ol><li><a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">Create full Microservice stack using JHipster Domain Language under 30 minutes</a></li><li><a href="https://medium.com/@deepu105/deploying-jhipster-microservices-on-azure-kubernetes-service-aks-fb46991746ba">Deploying JHipster Microservices on Azure Kubernetes Service (AKS)</a></li><li><a href="https://medium.freecodecamp.org/jhipster-microservices-with-istio-service-mesh-on-kubernetes-a7d0158ba9a3">How to set up JHipster microservices with Istio service mesh on Kubernetes</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5f0c3b2b1c8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xebialabs/continuous-delivery-of-microservices-with-xebialabs-a-k-a-devops-as-code-b5f0c3b2b1c8">Continuous delivery of Microservices with XebiaLabs — a.k.a DevOps as Code</a> was originally published in <a href="https://medium.com/xebialabs">XebiaLabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React components done right with TypeScript mapped and conditional types]]></title>
            <link>https://medium.com/free-code-camp/make-react-components-great-again-with-typescript-mapped-and-conditional-types-fa729bfc1a79?source=rss-28fde566f680------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa729bfc1a79</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Deepu K Sasidharan]]></dc:creator>
            <pubDate>Mon, 19 Nov 2018 16:36:21 GMT</pubDate>
            <atom:updated>2019-07-13T10:00:55.948Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*ypWl28F8NnBdxQaWIDm-YQ.jpeg" /></figure><p>You’ve probably heard about TypeScript. You may have heard someone claiming how great type safety is.</p><p>TypeScript is great. As someone who hates transpiling his code, I would definitely do it with TypeScript if I had to. So much has been said about TypeScript, and there isn’t really anything new that I can add. But I do believe that type safety is not all about making your code ugly with type definitions everywhere. So how can we write type-safe code without having to litter type declarations everywhere?</p><p>Type inference and advanced features like derived and dynamic types are the answer. Editors and IDEs we use are smart enough to handle code with inferred type gracefully without us having to see the types all the time visually. (Of course, they all usually show you the type when you hover over an inferred type.)</p><p>TypeScript has a very good type inference. As a rule of thumb, you can always start without declaring the type for any variable and see if the compiler infers it. With modern editors like VSCode, you can see this immediately. So set your tsconfig to the strict mode. Then start declaring types when the compiler complains.</p><p>Additionally, TypeScript 2.1 and 2.8 introduced a bunch of cool lookup types. Now you can dynamically infer types using different techniques like Intersection types, Union types, Index types, mapped types and conditional types.</p><h3>Index types</h3><p>Index types enable us to check properties and types of an interface or type dynamically using the keyof T (<strong>index type query operator) </strong>and T[K] (<strong>indexed access operator</strong>). Let&#39;s take the below interface for example.</p><pre>interface Person {<br>  name: string;<br>  age: number;<br>  address: string;<br>  sayHi: (msg: string) =&gt; string;<br>}</pre><p>The keyof T operator gets a union type of all the key names of the type T and hence keyof Person will give us &#39;name&#39; | &#39;age&#39; | &#39;address&#39; | sayHi&#39; as result.</p><p>The T[K] operator gets the type for the provided key. Person[&#39;name&#39;] will result in string and Person[<em>keyof</em> Person] will result in string | number | ((msg: string) =&gt; string).</p><h3>Mapped types</h3><p>Let us see what mapped types are. Let us say we have the below interface for a Person.</p><pre>interface Person {<br>  name: string;<br>  age: number;<br>  address: string;<br>  sayHi: (msg: string) =&gt; string;<br>}</pre><p>Now in every project, it is almost always a common requirement to have variations of a certain interface. For example, let’s say we need a read-only version of the person as below.</p><pre>interface ReadonlyPerson {<br>  readonly name: string;<br>  readonly age: number;<br>  readonly address: string;<br>  readonly sayHi: (msg: string) =&gt; string;<br>}</pre><p>In this case, we would have to replicate the Person interface and we have to keep them in sync manually. This is where mapped types will come in handy, so let us use the builtin mapped type, Readonly, for this.</p><pre><em>type</em> ReadonlyPerson  = <strong>Readonly</strong>&lt;Person&gt;</pre><p>If you hover over the ReadonlyPerson type you can see the inferred type as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*GLnLx-iMscyEMe9BQqCazg.png" /><figcaption>Inferred type view in VsCode</figcaption></figure><p>That is cool, right? Now we can create types from existing types and don’t have to worry about keeping them in sync. How does it work, what does Readonly&lt;Person&gt; do? Let’s take a look at the mapped type.</p><pre>type Readonly&lt;T&gt; = {<br>    readonly [K <strong>in</strong> keyof T]: T[K];<br>}</pre><p>The in operator from TypeScript does the trick here. It maps all the declarations of the existing type into the new type. The keyof operator provides the keys from our type for the mapping. Let us build our own mapped type.</p><p>Let us say we need a read-only Person interface where all the fields are nullable as well. We can build a mapped type as below for that.</p><pre>type ReadonlyNullablePerson = {<br>    readonly [P in keyof Person]: Person[P] | null;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*R24n6ufx4STh96tfldlgJw.png" /></figure><p>Let’s make it generic so that it can be used with any interface.</p><pre>type ReadonlyNullable&lt;T&gt; = {<br>    readonly [K in keyof T]: T[K] | null;<br>}</pre><pre>type ReadonlyNullablePerson  = ReadonlyNullable&lt;Person&gt;</pre><p>TypeScript includes Readonly&lt;T&gt;, Partial&lt;T&gt;, Pick&lt;T, K extends keyof T&gt; and Record&lt;K extends string, T&gt; as built-in mapped types. Pick and Record can be used as below, check them in your editor to see what types they produce.</p><pre>type PersonMinimal = Pick&lt;Person, &#39;name&#39; | &#39;age&#39;&gt;</pre><pre>type RecordedPerson = Record&lt;&#39;name&#39; | &#39;address&#39;, string&gt;</pre><p>For every other use case, you can build your own mapped types.</p><h3>Conditional types</h3><blockquote>A conditional type selects one of two possible types based on a condition expressed as a type relationship test.</blockquote><p>Let us look at an example.</p><pre>type Foo&lt;T, U&gt; = T extends U ? string : boolean</pre><pre>interface Me {}<br>interface You extends Person {}</pre><pre>type FooBool = Foo&lt;Me, Person&gt; // will result in boolean<br>type FooString = Foo&lt;You, Person&gt; // will result in string</pre><p>The type dynamically inferred from Foo&lt;T, U&gt; will be either string or boolean depending on what the first generic is extended from.</p><p>Let us see how we can mix conditional types with mapped types to infer a new type from Person which only includes the non-function properties.</p><pre>type NonFunctionPropNames&lt;T&gt; = {<br>  [K in keyof T]: T[K] extends Function ? never : K<br>}[keyof T];</pre><pre>type NonFunctionProps&lt;T&gt; = Pick&lt;T, NonFunctionPropNames&lt;T&gt;&gt;</pre><pre>type PersonProps = NonFunctionProps&lt;Person&gt;</pre><pre>// Produces the below type<br>// type PersonProps = {<br>//     name: string;<br>//     age: number;<br>//     address: string;<br>// }</pre><p>We first get all the non-function property names from the interface. Then use the <strong>Pick</strong> mapped type to pick those from the interface to form the new interface.</p><p>TypeScript provides following inbuilt conditional types:</p><ul><li>Exclude&lt;T, U&gt; – Exclude from T those types that are assignable to U.</li><li>Extract&lt;T, U&gt; – Extract from T those types that are assignable to U.</li><li>NonNullable&lt;T&gt; – Exclude null and undefined from T.</li><li>ReturnType&lt;T&gt; – Obtain the return type of a function type.</li><li>InstanceType&lt;T&gt; – Obtain the instance type of a constructor function type.</li></ul><h3>Let us put it into use</h3><p>These advanced types become even more powerful when you combine them together. Let’s see some practical uses of this in React.</p><h4>React component and Redux reducer in ES6</h4><p>Let see a simple React component with a reducer written in ES6. Take a look at <strong><em>index.jsx</em></strong> in the below code sandbox:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F40n3y52qlx%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Deditor&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F40n3y52qlx%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Deditor&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F40n3y52qlx%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7b1b314a38b72ea94fd4ba338e7b06f/href">https://medium.com/media/b7b1b314a38b72ea94fd4ba338e7b06f/href</a></iframe><p>As you can see, we use the prop-types library to define the component props. It is not the most efficient way, as it includes considerable overhead during development. It doesn’t provide full type safety anyway.</p><h4>React component and Redux reducer in TypeScript</h4><p>Now let us convert this simple example to TypeScript so that it&#39;s type safe. Take a look at <strong><em>index.tsx</em></strong> in the below code sandbox:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fznv36k09op%3Fhidenavigation%3D1%26view%3Deditor&amp;src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fznv36k09op%3Fhidenavigation%3D1%26view%3Deditor&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/b478c97b6544b249c81a251203de076c/href">https://medium.com/media/b478c97b6544b249c81a251203de076c/href</a></iframe><p>As you can see, the code is more type-safe now. It is also much more verbose even without PropTypes library and all the type inference.</p><h4>React component and Redux reducer in TypeScript with advanced types</h4><p>Now let us apply the advanced types that we learned to make this example less verbose and even more type safe. Take a look at <strong><em>index.tsx</em></strong> in the below code sandbox:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fzq7w69p57x%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Deditor&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fzq7w69p57x%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Deditor&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fzq7w69p57x%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf44780caff06f292fef763cb2bf360d/href">https://medium.com/media/bf44780caff06f292fef763cb2bf360d/href</a></iframe><p>As you can see, we used Readonly and ReturnType mapping along with some other type inference techniques to write a more type-safe but less verbose version of the component.</p><h3>Conclusion</h3><p>If you are using React with TypeScript, then these are some of the techniques you must apply. If you are considering a type system for React, then look no further than TypeScript. It has great features, great tooling, excellent IDE/Editor support and an awesome community.</p><p>I gave a talk on TypeScript for Devoxx 2018, and you can see the video and slides if you like here.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FSBwGH4kbkms%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSBwGH4kbkms&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FSBwGH4kbkms%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/322cd9297418e325b945df3c5e20fdd3/href">https://medium.com/media/322cd9297418e325b945df3c5e20fdd3/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fspeakerdeck.com%2Fplayer%2Fffe22480dbfd4c1f83f66c380bba2283&amp;url=https%3A%2F%2Fspeakerdeck.com%2Fdeepu105%2Fwhy-you-should-love-typescript-a-practical-guide&amp;image=https%3A%2F%2Fspeakerd.s3.amazonaws.com%2Fpresentations%2Fffe22480dbfd4c1f83f66c380bba2283%2Fslide_0.jpg%3F476363&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=speakerdeck" width="710" height="399" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad58e5545532118280cef500aa06a090/href">https://medium.com/media/ad58e5545532118280cef500aa06a090/href</a></iframe><p>Check out my book “<em>Full Stack Development with JHipster</em>” on <a href="https://www.amazon.com/Stack-Development-JHipster-Deepu-Sasidharan/dp/178847631X">Amazon</a> and <a href="https://www.packtpub.com/application-development/full-stack-development-jhipster">Packt</a> if you like to learn about Full stack development with an awesome stack.</p><p>If you like JHipster don’t forget to give it a star on <a href="https://github.com/jhipster/generator-jhipster">Github</a>.</p><p>If you like this article, please leave some claps (Did you know that you can clap multiple times? 😁 )</p><p>You can follow me on <a href="https://twitter.com/deepu105">Twitter</a> and <a href="https://www.linkedin.com/in/deepu05/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa729bfc1a79" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/make-react-components-great-again-with-typescript-mapped-and-conditional-types-fa729bfc1a79">React components done right with TypeScript mapped and conditional types</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up JHipster microservices with Istio service mesh on Kubernetes]]></title>
            <link>https://medium.com/free-code-camp/jhipster-microservices-with-istio-service-mesh-on-kubernetes-a7d0158ba9a3?source=rss-28fde566f680------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7d0158ba9a3</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Deepu K Sasidharan]]></dc:creator>
            <pubDate>Sat, 17 Nov 2018 16:01:37 GMT</pubDate>
            <atom:updated>2019-07-24T06:10:42.387Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sed7vszGYvi40oa1F7iVzg.png" /></figure><p>You can find a more up to date version of this post that uses JHipster 6 and latest Istio &amp; Kubernetes versions <a href="https://dev.to/deepu105/how-to-set-up-java-microservices-with-istio-service-mesh-on-kubernetes-5bkn">here</a>.</p><p>Istio is the coolest kid on the DevOps and Cloud block now. For those of you who aren’t following close enough — <a href="https://istio.io/docs/concepts/what-is-istio/">Istio is a service mesh</a> for distributed application architectures, especially the ones that you run on the cloud with Kubernetes. Istio plays extremely nice with Kubernetes, so nice that you might think that it’s part of Kubernetes.</p><p>If you are still wondering, what the heck is a service mesh or Istio? then let&#39;s have an overview of Istio.</p><p>Istio provides the following functionality in a distributed application architecture:</p><ul><li>Service discovery — Traditionally provided by platforms like <a href="https://github.com/Netflix/eureka/wiki">Netflix Eureka </a>or <a href="https://www.consul.io/">Consul</a>.</li><li>Automatic load balancing — You might have used <a href="https://github.com/Netflix/zuul/wiki">Netflix Zuul</a> for this.</li><li>Routing, circuit breaking, retries, fail-overs, fault injection — Think of <a href="https://github.com/Netflix/ribbon/wiki">Netflix Ribbon</a>, <a href="https://github.com/Netflix/Hystrix">Hytrix</a> and so on.</li><li>Policy enforcement for access control, rate limiting, A/B testing, traffic splits, and quotas — Again you might have used Zuul to do some of these.</li><li>Metrics, logs, and traces — Think of <a href="https://www.elastic.co/elk-stack">ELK</a> or <a href="https://cloud.google.com/stackdriver/">Stack driver</a></li><li>Secure service-to-service communication</li></ul><p>Below is the architecture of Istio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_STCerKXb4L3Hutyn4P5Gw.png" /><figcaption>Istio architecture</figcaption></figure><p>It can be classified into 2 distinct planes.</p><p><strong>Data plane</strong>: Is made of <a href="https://www.envoyproxy.io/">Envoy</a> proxies deployed as sidecars to the application containers. They control all the incoming and outgoing traffic to the container.</p><p><strong>Control plane</strong>: It uses Pilot to manages and configure the proxies to route traffic. It also configures Mixer to enforce policies and to collect telemetry. It also has other components like Citadel, to manage security, and Galley, to manage configurations.</p><p>Istio also configures an instance of <a href="https://grafana.com/">Grafana</a>, <a href="https://prometheus.io/">Prometheus</a> and <a href="https://www.jaegertracing.io/">Jaeger</a> for Monitoring and Observability. You can use this or use your existing monitoring stack as well.</p><p>I hope this provides an overview of Istio, now let&#39;s focus on the goal of this article.</p><h3>Devoxx 2018</h3><p>I did a talk at <a href="https://dvbe18.confinabox.com/talk/XCM-6395/JHipster_5_-_What&#39;s_new_and_noteworthy">Devoxx 2018</a> along with <a href="https://www.julien-dubois.com/">Julien Dubois</a> doing the same demo and promised that I’d write a detailed blog about it.</p><h3>𝔻𝕖𝕖𝕡𝕦 𝕂 𝕊𝕒𝕤𝕚𝕕𝕙𝕒𝕣𝕒𝕟 on Twitter</h3><p>Had a wonderful time at #devoxx2018, sad that I had to leave early due to work commitments. Had 3 talks and 1 of them with my friend and the real hipster @juliendubois, all the talks were well received and I&#39;m grateful for all the positive feedback.</p><p>You can watch the video to see JHipster + Istio in action.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FNPToZd0PxbI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DNPToZd0PxbI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FNPToZd0PxbI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb8bc4342122abb0177959d9d6c271d7/href">https://medium.com/media/eb8bc4342122abb0177959d9d6c271d7/href</a></iframe><p>You can watch the slides on Speaker Deck as well.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fspeakerdeck.com%2Fplayer%2Fd5813577c59043ca8753d9be01dc41ac&amp;url=https%3A%2F%2Fspeakerdeck.com%2Fdeepu105%2Fjhipster-5-whats-new-and-noteworthy&amp;image=https%3A%2F%2Fspeakerd.s3.amazonaws.com%2Fpresentations%2Fd5813577c59043ca8753d9be01dc41ac%2Fslide_0.jpg%3F476361&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=speakerdeck" width="710" height="399" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3015a3fdf2bb73e3c79267d825da3f7/href">https://medium.com/media/e3015a3fdf2bb73e3c79267d825da3f7/href</a></iframe><h3>Preparing the Kubernetes cluster</h3><p>First, let us prepare a Kubernetes cluster to deploy Istio and our application containers. Follow the instructions for any one of the platforms you prefer.</p><h4>Prerequisites</h4><p><a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/"><strong>kubectl</strong></a>: The command line tool to interact with Kubernetes. Install and configure it.</p><h4>Create a cluster on Azure Kubernetes Service(AKS)</h4><p>If you are going to use Azure, then install <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest"><strong>Azure CLI</strong></a> to interact with Azure. Install and log in with your Azure account (you can create a <a href="https://azure.microsoft.com/en-us/free/">free account</a> if you don’t have one already).</p><p>First let us create a resource group. You can use any region you like here instead of East US.</p><pre>$ az group create --name eCommerceCluster --location eastus</pre><p>Create the Kubernetes cluster:</p><pre>$ az aks create \<br>--resource-group eCommerceCluster \<br>--name eCommerceCluster \<br><strong>--node-count 4</strong> \<br><strong>--kubernetes-version 1.11.4</strong> \<br>--enable-addons monitoring \<br>--generate-ssh-keys</pre><p>The node-count flag is important as the setup requires at least four nodes with the default CPU to run everything. You can try to use a higher kubernetes-version if it is supported, else stick to 1.11.4</p><p>The cluster creation could take while so sit back and relax. 🍹</p><p>Once the cluster is created, fetch its credentials to be used from kubectl by running the below command. It automatically injects the credentials to your kubectl configuration under <strong><em>~/.kube/config</em></strong></p><pre>$ az aks get-credentials \<br>--resource-group eCommerceCluster \<br>--name eCommerceCluster</pre><p>You can view the created cluster in the Azure portal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yfLnHHc_N7VCkEY9vjNciQ.png" /><figcaption>Kubernetes cluster in AKS</figcaption></figure><p>Run kubectl get nodes to see it in the command line and to verify that kubectl can connect to your cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*k8xsRqQsvnquUhGPAh9TsA.png" /><figcaption>Cluster Nodes</figcaption></figure><p>Proceed to the <strong>Install and setup Istio</strong> section.</p><h4>Create a cluster on Google Kubernetes Engine(GKE)</h4><p>If you are going to use Google Cloud Platform(GCP) then install <a href="https://cloud.google.com/sdk/docs/"><strong>Gcloud CLI</strong></a> to interact with GCP. Install and log in with your GCP account (you can create a <a href="https://console.cloud.google.com/freetrial">free account</a> if you don’t have one already).</p><p>First, we need a GCP project, you can either use an existing project that you have or create a new one using GCloud CLI with below command:</p><pre>$ gcloud projects create jhipster-demo-deepu</pre><p>Set the project you want to use as the default project:</p><pre>$ gcloud config set project jhipster-demo-deepu</pre><p>Now let us create a cluster for our application with the below command:</p><pre>$ gcloud container clusters create hello-hipster \</pre><pre>   --cluster-version 1.10 \</pre><pre><strong>   --num-nodes 4</strong> \</pre><pre><strong>   --machine-type n1-standard-2</strong></pre><p>The num-nodes and machine-type flags are important as the setup requires at least four nodes with a bigger CPU to run everything. You can try to use a higher cluster-version if it is supported, else stick to 1.10.</p><p>The cluster creation could take while so sit back and relax.</p><p>Once the cluster is created, fetch its credentials to be used from kubectl by running the below command. It automatically injects the credentials to your kubectl configuration under <strong><em>~/.kube/config</em></strong></p><pre>$ gcloud container clusters get-credentials hello-hipster</pre><p>You can view the created cluster in the GCP GUI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*ZxNbIG4vqWJymTLweJpPyQ.png" /><figcaption>Kubernetes cluster on GKE</figcaption></figure><p>Run kubectl get nodes to see it in the command line and to verify that kubectl can connect to your cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*F5Qcd_GS_GSuA1PsJE7gvA.png" /><figcaption>Cluster Nodes</figcaption></figure><h3>Install and setup Istio</h3><p>Install Istio on your machine by following these steps:</p><pre>$ cd ~/</pre><pre>$ export ISTIO_VERSION=1.0.2</pre><pre>$ curl -L https://git.io/getLatestIstio | sh -</pre><pre>$ ln -sf istio-$ISTIO_VERSION istio</pre><pre>$ export PATH=~/istio/bin:$PATH</pre><p>Make sure to use version <strong>1.0.2</strong> since the latest version seems to have issues connecting to the MySQL database containers.</p><p>Now let us install Istio on our Kubernetes cluster by applying the provided Kubernetes manifests and helm templates from Istio.</p><pre>$ kubectl apply -f ~/istio/install/kubernetes/helm/istio/templates/crds.yaml<br>$ kubectl apply -f ~/istio/install/kubernetes/istio-demo.yaml \<br>    --as=admin --as-group=system:masters</pre><p>Wait for the pods to run, these will be deployed to the istio-system namespace.</p><pre>$ watch kubectl get pods -n istio-system</pre><p>Once the pods are in running status, exit the watch loop and run the below to get the Ingress gateway service details. This is the only service that is exposed to an external IP.</p><pre>$ kubectl get svc istio-ingressgateway -n istio-system</pre><pre>NAME                   TYPE           CLUSTER-IP     EXTERNAL-IP<br>istio-ingressgateway   LoadBalancer   10.27.249.83   35.195.81.130</pre><p>The external IP is very important here, let us save this to an environment variable so that we can use it in further commands.</p><pre>$ export \<br>  INGRESS_IP=$(kubectl -n istio-system get svc \<br>  istio-ingressgateway \<br>  -o jsonpath=&#39;{.status.loadBalancer.ingress[0].ip}&#39;)</pre><p>Now our Kubernetes cluster is ready for Istio. 🎉</p><p><em>For advanced Istio setup options refer to </em><a href="https://istio.io/docs/setup/kubernetes/"><em>https://istio.io/docs/setup/kubernetes/</em></a></p><h3>Creating the microservice application stack</h3><p>In one of my <a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">previous posts</a>, I showcased how to create a full stack microservice architecture using <strong>JHipster</strong> and <strong>JDL</strong>. You can read the post <a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">here</a> if you want to learn more details about it. For this exercise, we will use the same application but we will not use the Eureka service discovery option we used earlier. Also, note that the store application is further split into Gateway and Product applications.</p><h4>Architecture</h4><p>Here is the architecture of the microservice that we are going to create and deploy today.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UmNJ-Ue362-OltPOxt-OFQ.png" /><figcaption>Microservice architecture with Istio</figcaption></figure><p>It has a gateway application and three microservice applications. Each of them has its own database. You can see that each application has an Envoy proxy attached to the pod as a sidecar. Istio control plane components are also deployed to the same cluster along with Prometheus, Grafana, and Jaeger.</p><p>The Ingress gateway from Istio is the only entry point for traffic and it routes traffic to all microservices accordingly. Telemetry is collected from all the containers running in the cluster, including the applications, databases, and Istio components.</p><p>Compared to the architecture of the original application <a href="https://medium.com/@deepu105/deploying-jhipster-microservices-on-azure-kubernetes-service-aks-fb46991746ba">here</a>, you can clearly see that we replaced the JHipster registry and Netflix OSS components with Istio. The ELK monitoring stack is replaced with Prometheus, Grafana and Jaeger configured by Istio. Here is the original architecture diagram without Istio for a quick visual comparison.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-6_dz1-aYXQ-fzWEuJcRw.png" /><figcaption>Microservice architecture with Netflix OSS</figcaption></figure><h4>Application JDL</h4><p>Let’s take a look at the modified JDL declaration. You can see that we have declared serviceDiscoveryType no here since we will be using Istio for that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a02b6329b1450e784592209bb4888ff/href">https://medium.com/media/4a02b6329b1450e784592209bb4888ff/href</a></iframe><h4>Deployment JDL</h4><p>JHipster version 5.7.0 introduced support for deployment declaration straight in the JDL</p><h3>𝔻𝕖𝕖𝕡𝕦 𝕂 𝕊𝕒𝕤𝕚𝕕𝕙𝕒𝕣𝕒𝕟 on Twitter</h3><p>Towards the future of #JHipster, #ScaffoldingAsCode Check this out. Soon you will be able to define apps, entities and deployment options with a single JDL file and generate everything with a single command. Hopefully, we can demo this for @Devoxx https://t.co/u28cwaymfc</p><p>We have the below in our JDL which declares our Kubernetes deployment:</p><pre>deployment {<br>  deploymentType kubernetes<br>  appsFolders [store, invoice, notification, product]<br>  dockerRepositoryName &quot;deepu105&quot;<br>  <strong>serviceDiscoveryType no</strong><br>  <strong>istio autoInjection<br>  istioRoute true<br>  kubernetesServiceType Ingress</strong><br>  kubernetesNamespace jhipster<br>  <strong>ingressDomain &quot;35.195.81.130.nip.io&quot;</strong><br>}</pre><p>The serviceDiscoveryType is disabled and we have enabled Istio with autoInjection support — the Envoy sidecars are injected automatically for the selected applications. Istio routes are also generated for the applications by enabling istioRoute option.</p><p>The kubernetesServiceType is set as Ingress, which is very important as Istio can only work with an Ingress controller service type. For Ingress, we need to set the domain DNS and this is where the Istio ingress gateway IP is needed. Now we need a DNS for our IP. For real usecases, you should map a DNS for the IP, but for testing and demo purposes we can use a wildcard DNS service like <a href="http://nip.io/"><strong>nip.io</strong></a> to resolve our IP. Just append nip.io to our IP and use that as the ingress domain.</p><h4>Generate the applications and deployment manifests</h4><p>Now that our JDL is ready, let us scaffold our applications and Kubernetes manifests. Create a new directory and save the above JDL in the directory. Let us name it <strong><em>app-istio.jdl</em></strong> and then run the import-jdl command.</p><pre>$ mkdir istio-demo &amp;&amp; cd istio-demo<br>$ jhipster import-jdl app-istio.jdl</pre><p>This will generate all the applications and install the required NPM dependencies in each of them. Once the applications are generated the deployment manifests will be generated and some useful instruction will be printed to the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ROg2XrRkHVHA4Xib" /><figcaption>Generation output</figcaption></figure><p>Open the generated code in your favorite IDE/Editor and explore the code.</p><h3>Deploy to Kubernetes cluster using Kubectl</h3><p>Now let us build and deploy our applications. Run the ./gradlew bootWar -Pprod jibDockerBuild command in the store, product, invoice, and notification folders to build the docker images. Once the images are built, push them to the docker repo with these commands:</p><pre>$ docker image tag store deepu105/store</pre><pre>$ docker push deepu105/store</pre><pre>$ docker image tag invoice deepu105/invoice</pre><pre>$ docker push deepu105/invoice</pre><pre>$ docker image tag notification deepu105/notification</pre><pre>$ docker push deepu105/notification</pre><pre>$ docker image tag product deepu105/product</pre><pre>$ docker push deepu105/product</pre><p>Once the images are pushed, navigate into the generated Kubernetes directory and run the provided startup script. (If you are on windows you can run the steps in <strong><em>kubectl-apply.sh</em></strong> manually one by one.)</p><pre>$ cd kubernetes<br>$ ./kubectl-apply.sh</pre><p>Run watch kubectl get pods -n jhipster to monitor the status.</p><h3>Deployed applications</h3><p>Once all the pods are in running status we can explore the deployed applications</p><h4>Application gateway</h4><p>The store gateway application is the entry point for our microservices. Get the URL for the store app by running echo store.$INGRESS_IP.nip.io, we already stored the INGRESS_IP to environment variables while creating the Istio setup. Visit the URL in your favorite browser and explore the application. Try creating some entities for the microservices:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qd6y_H-ObCeorQkg" /><figcaption>Store gateway application</figcaption></figure><h4>Monitoring</h4><p>Istio setup includes Grafana and Prometheus configured to collect and show metrics from our containers. Let&#39;s take a look.</p><p>By default, only the Ingress gateway is exposed to external IP and hence we will use kubectl port forwarding to set up a secure tunnel to the required services</p><p>Let us create a tunnel for Grafana:</p><pre>$ kubectl -n istio-system \<br>port-forward $(kubectl -n istio-system get pod \</pre><pre>-l app=grafana -o jsonpath=&#39;{.items[0].metadata.name}&#39;) 3000:3000</pre><p>Open <a href="/service/localhost:3000">localhost:3000</a> to view the Grafana dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zaX0S8relpT4q__T" /><figcaption>Grafana dashboard for the Store application</figcaption></figure><p>Grafana uses the metrics scrapped by Prometheus. We can look at Prometheus directly by creating a tunnel for it and opening <a href="/service/localhost:9090">localhost:9090</a>:</p><pre>$ kubectl -n istio-system \<br>port-forward $(kubectl -n istio-system get pod -l \</pre><pre>app=prometheus -o jsonpath=&#39;{.items[0].metadata.name}&#39;) 9090:9090</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W4obHNne_wQJfAuU" /><figcaption>Prometheus dashboard</figcaption></figure><h4>Observability</h4><p>Istio configures Jaeger for distributed tracing and service graph for service observability. Let us take a look at them.</p><p>Create a tunnel for Jaeger and open <a href="/service/localhost:16686">localhost:16686</a></p><pre>$ kubectl -n istio-system \<br>port-forward $(kubectl -n istio-system get pod -l \</pre><pre>app=jaeger -o jsonpath=&#39;{.items[0].metadata.name}&#39;) 16686:16686</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cyhS1_B0LFO54e48" /><figcaption>Jaeger tracing dashboard</figcaption></figure><p>You can make some requests in the application and find it in the tracing dashboard by querying for the service. Click on the request to see tracing details:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X4XtKtIeMapPEyt_nfvftA.png" /><figcaption>Tracing for product category listing request</figcaption></figure><p>Let us now create a tunnel for the service graph and open it in <a href="/service/localhost:8080/force/forcegraph.html">localhost:8080/force/forcegraph.html</a>:</p><pre>$ kubectl -n istio-system \<br>port-forward $(kubectl -n istio-system get pod -l \</pre><pre>app=servicegraph -o jsonpath=&#39;{.items[0].metadata.name}&#39;) 8088:8088</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4nQUsagF6TVupK-5" /><figcaption>Istio service graph</figcaption></figure><h3>Conclusion</h3><p>Istio provides building blocks to build distributed microservices in a more Kubernetes-native way and takes the complexity and responsibility of maintaining those blocks away from you. This means you do not have to worry about maintaining the code or deployments for service discovery, tracing and so on.</p><p>Istio documentation says</p><blockquote>Deploying a microservice-based application in an Istio service mesh allows one to externally control service monitoring and tracing, request (version) routing, resiliency testing, security and policy enforcement, etc., in a consistent way across the services, for the application as a whole.</blockquote><p>Werner Vogels (CTO of AWS) quoted at AWS Re:Invent</p><blockquote>“In the future, all the code you ever write will be business logic.”</blockquote><p>Istio Service mesh helps with that statement. This lets you worry only about the applications that you are developing and with JHipster that future is truly here and you just need to worry about writing your business logic.</p><p>While this is great, it is not a silver bullet. Keep in mind that Istio is fairly new compared to other stable and battle-tested solutions like JHipster Registry (Eureka) or Consul.</p><p>Also, another thing to keep in mind is the resource requirements. The same microservices with JHipster Registry or Consul can be deployed to a 2 node cluster with 1 vCPU and 3.75 GB of memory per node in GCP while you need a 4 node cluster with 2 vCPUs and 7.5 GB of memory per node for Istio enabled deployments. The default Kubernetes manifest from Istio doesn’t apply any request limits for resources, and by adding and tuning those, the minimum requirement could be reduced. But still I don’t think you can get it as low as that is needed for the JHipster registry option.</p><p>In a real-world use case, the advantages of not having to maintain the complex parts of your infra vs having to pay for more resources might be a decision that has to be taken based on your priorities and goals.</p><p>A huge shout out to <a href="https://twitter.com/saturnism">Ray Tsang</a> for helping me figure out an optimal cluster size for this application. Also a huge thank you from myself and the community to both Ray and <a href="https://twitter.com/humourmind">Srinivasa Vasu</a> for adding the Istio support to JHipster.</p><p>JHipster provides a great Kubernetes setup to start with which you can further tweak as per your needs and platform. The Istio support is recent and will improve further over time, but it&#39;s still a great starting point especially to learn.</p><p>To learn more about JHipster and Full stack development, check out my book “<em>Full Stack Development with JHipster</em>” on <a href="https://www.amazon.com/Stack-Development-JHipster-Deepu-Sasidharan/dp/178847631X">Amazon</a> and <a href="https://www.packtpub.com/application-development/full-stack-development-jhipster">Packt</a>.</p><p>There is a great Istio tutorial from Ray Tsang <a href="https://docs.google.com/document/d/1Qo8o5C4UpGwMF7Mg02kLTaU4-xCSfJjLcnIFNveMEEA">here</a>.</p><p>If you like JHipster don’t forget to give it a star on <a href="https://github.com/jhipster/generator-jhipster">Github</a>.</p><p>If you like this article, please leave some claps (Did you know that you can clap multiple times in Medium? 😁) I hope to write more about Istio in the near future.</p><p>You can follow me on <a href="https://twitter.com/deepu105">Twitter</a> and <a href="https://www.linkedin.com/in/deepu05/">LinkedIn</a>.</p><p>My other related posts:</p><ol><li><a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">Create full Microservice stack using JHipster Domain Language under 30 minutes</a></li><li><a href="https://medium.com/@deepu105/deploying-jhipster-microservices-on-azure-kubernetes-service-aks-fb46991746ba">Deploying JHipster Microservices on Azure Kubernetes Service (AKS)</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7d0158ba9a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/jhipster-microservices-with-istio-service-mesh-on-kubernetes-a7d0158ba9a3">How to set up JHipster microservices with Istio service mesh on Kubernetes</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying JHipster Microservices on Azure Kubernetes Service (AKS)]]></title>
            <link>https://medium.com/jhipster/deploying-jhipster-microservices-on-azure-kubernetes-service-aks-fb46991746ba?source=rss-28fde566f680------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb46991746ba</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[jhipster]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Deepu K Sasidharan]]></dc:creator>
            <pubDate>Sun, 30 Sep 2018 22:59:26 GMT</pubDate>
            <atom:updated>2019-04-01T11:54:33.481Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nVYYKBoVYcKUcaGIIGSgmA.png" /></figure><p>If you are developing and deploying applications to production, especially cloud, you would have heard about <a href="https://kubernetes.io/"><strong>Kubernetes</strong></a><strong>. </strong>Kubernetes(<strong>k8s</strong>) is a container orchestration platform originally developed by Google and makes deploying containerized/dockerized applications to production more manageable and scalable.</p><p><a href="https://kubernetes.io/"><strong>Kubernetes</strong></a> has been crowned as the undeniable champion of container orchestration for a while now and every other <strong>*KS</strong> offering that we see sprouting up are testimonials for that. The <strong>K</strong> obviously stands for Kubernetes and <strong>S/E</strong> stands for Service/Engine and the first letter stands for the product offering it. So far we have <a href="https://docs.microsoft.com/en-us/azure/aks/"><strong>AKS</strong></a>(Azure), <a href="https://cloud.google.com/kubernetes-engine/"><strong>GKE</strong></a>(Google), and <a href="https://aws.amazon.com/eks/"><strong>EKS</strong></a>(Amazon ECS) and <a href="https://content.pivotal.io/pivotal-container-service-pks"><strong>PKS</strong></a>(Pivotal) and also some flavors from <a href="https://cloud.oracle.com/en_US/containers/kubernetes-engine#">Oracle</a> and RedHat(read <a href="https://www.redhat.com/en/technologies/cloud-computing/openshift">Openshift</a>)</p><p>One of my colleagues have written a <a href="https://blog.xebialabs.com/2017/12/12/future-container-solutions-will-k-shaped/">nice article</a> about it, I highly recommend you read it as well.</p><p>In this article, we will see how we can deploy a microservice architecture created by JHipster to Azure Kubernetes Service.</p><p>Azure Kubernetes Service(AKS) is the managed Kubernetes platform offering from Microsoft to host your containerized applications.</p><h4>Creating the microservice application</h4><p>In one of my <a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">previous posts</a>, I showcased how to create a full stack microservice architecture using <strong>JHipster</strong> and <strong>JDL</strong>, read the post <a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">here</a> if you want to learn more details about it. For this exercise, we will use the same application.</p><p>Let us recap the steps required.</p><p>Create a JDL file, let’s say app.jdl, and copy the below content into it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df6446c8ad65aae2af8c1419b61d2b52/href">https://medium.com/media/df6446c8ad65aae2af8c1419b61d2b52/href</a></iframe><p>Now create a directory called <strong>ecommerce</strong> and navigate into it. Run the JHipster import-jdl command. It could take a few minutes, especially the NPM install step.</p><pre>$ mkdir ecommerce &amp;&amp; cd ecommerce<br>$ jhipster import-jdl app.jdl</pre><p>Once the JHipster process is complete, you will see that we have our store gateway, invoice service and notification service created and ready for us. The process until this is explained in more detail in my previous post <a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">here</a> and you can deploy the application locally using Docker as explained in that post. If you haven’t done that before I strongly suggest that step so that you get an idea of the application and you also can make sure it works locally on your machine.</p><h4>Generating the Kubernetes configuration</h4><p>Now that our application is ready, let us create the required configurations for Kubernetes using JHipster.</p><p>In the ecommerce folder, we created earlier, create a new directory, let&#39;s call in k8s so that we get the below structure.</p><pre>├── app.jdl<br>├── invoice<br>├── <strong>k8s</strong><br>├── notification<br>└── store</pre><p>Create the k8s directory and navigate to it. Now run the JHipster Kubernetes command there.</p><pre>$ mkdir k8s &amp;&amp; cd k8s<br>$ <strong>jhipster kubernetes</strong></pre><p>The generator will ask you a few questions and choose the answers as highlighted below, as you can see the questions are very similar to the ones asked by jhipster docker-compose command. For the “base Docker repository name” provide your own docker hub account id(For example, my Docker Hub id is <a href="https://hub.docker.com/u/deepu105/">deepu105</a>). For real-world use cases, you could also use a private image repository like the <a href="https://docs.microsoft.com/en-us/azure/aks/tutorial-kubernetes-prepare-acr">Azure Container Registry</a> and in that case, you would have to provide the ACR login server name here. For now, let us keep it simple.</p><pre>⎈ Welcome to the JHipster Kubernetes Generator ⎈<br>Files will be generated in folder: /home/deepu/workspace/temp/ecommerce/k8s<br>✔ Docker is installed</pre><pre>? Which *type* of application would you like to deploy? <strong>Microservice application</strong></pre><pre>? Enter the root directory where your gateway(s) and microservices are located <strong>../</strong></pre><pre>3 applications found at /home/deepu/workspace/temp/ecommerce/<br>? Which applications do you want to include in your configuration? <strong>invoice, notification, store</strong></pre><pre>? Do you want to setup monitoring for your applications ? <strong>No</strong></pre><pre>? Which applications do you want to use with clustered databases (only available with MongoDB and Couchbase)? </pre><pre>JHipster registry detected as the service discovery and configuration provider used by your apps</pre><pre>? Enter the admin password used to secure the JHipster Registry <strong>admin</strong></pre><pre>? What should we use for the Kubernetes namespace? <strong>default</strong></pre><pre>? What should we use for the base Docker repository name? <strong>&lt;your Docker hub account id&gt;</strong></pre><pre>? What command should we use for push Docker image to repository? <strong>docker push</strong></pre><pre>? Do you want to configure Istio? <strong>Not required</strong></pre><pre>? Choose the kubernetes service type for your edge services <strong>LoadBalancer - Let a kubernetes cloud provider automatically assign an IP</strong></pre><p>The generator will go to work with this and will create the following files and output.</p><pre>   create invoice/invoice-deployment.yml<br>   create invoice/invoice-service.yml<br>   create invoice/invoice-mysql.yml<br>   create notification/notification-deployment.yml<br>   create notification/notification-service.yml<br>   create notification/notification-mongodb.yml<br>   create store/store-deployment.yml<br>   create store/store-service.yml<br>   create store/store-mysql.yml<br>   create README.md<br>   create registry/jhipster-registry.yml<br>   create registry/application-configmap.yml<br>   create kubectl-apply.sh</pre><pre>WARNING! Kubernetes configuration generated with missing images!</pre><pre>To generate the missing Docker image(s), please run:</pre><pre>  <strong>./gradlew -Pprod bootWar buildDocker</strong> in /home/deepu/workspace/temp/ecommerce/<strong>invoice</strong></pre><pre>  <strong>./gradlew -Pprod bootWar buildDocker</strong> in /home/deepu/workspace/temp/ecommerce/<strong>notification</strong></pre><pre>  <strong>./gradlew -Pprod bootWar buildDocker</strong> in /home/deepu/workspace/temp/ecommerce/<strong>store</strong></pre><pre>WARNING! You will need to push your image to a registry. If you have not done so, use the following commands to tag and push the images:</pre><pre>  docker image tag <strong>invoice</strong> <strong>deepu105</strong>/<strong>invoice</strong><br>  docker push <strong>deepu105</strong>/<strong>invoice</strong></pre><pre>  docker image tag <strong>notification</strong> <strong>deepu105</strong>/<strong>notification</strong><br>  docker push <strong>deepu105</strong>/<strong>notification</strong></pre><pre>  docker image tag <strong>store</strong> <strong>deepu105</strong>/<strong>store</strong><br>  docker push <strong>deepu105</strong>/<strong>store</strong></pre><pre>You can deploy all your apps by running the following script:<br>  <strong>./kubectl-apply.sh</strong></pre><pre>Use these commands to find your application&#39;s IP addresses:<br>  kubectl get svc store</pre><pre>Congratulations, JHipster execution is complete!</pre><p>As you can see the generator creates all the required Kubernetes configuration files and prints out useful information to proceed further (Note that the docker hub id you provided will be in the instructions in place of <strong>deepu105</strong> here). Go through the generated k8s files and familiarize yourself.</p><p><strong>EDIT: This issue has been fixed in the latest version of JHipster and hence you can skip this step</strong>. Due to an <a href="https://github.com/jhipster/generator-jhipster/issues/8422">open issue in JHipster</a>, we would have to make some adjustments to the generated Kubernetes configuration. This is also why I didn&#39;t enable monitoring with Elastic(ELK) stack.</p><p>First, we need to modify the filek8s/notification/notification-mongodb.yml to simplify it from a stateful set to a simple deployment. The stateful set configuration is required if you need to cluster your MongoDB and is the recommended setup, I’ll be updating the post once the bug is fixed. Change the content of the file to below</p><pre>apiVersion: apps/v1beta1<br>kind: <strong>Deployment</strong><br>metadata:<br>  name: notification-mongodb<br>  namespace: default<br>spec:<br>  replicas: 1<br>  template:<br>    metadata:<br>      labels:<br>        app: notification-mongodb<br>    spec:<br>      volumes:<br>      - name: data<br>        emptyDir: {}<br>      containers:<br>      - name: mongodb<br>        image: mongo:3.6.3<br>        ports:<br>        - name: peer<br>          containerPort: 27017<br>        volumeMounts:<br>        - name: data<br>          mountPath: /data/db/<br>---<br># Headless service for DNS record<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  annotations:<br>    service.alpha.kubernetes.io/tolerate-unready-endpoints: &quot;true&quot;<br>  name: notification-mongodb<br>  namespace: default<br>spec:<br>  type: ClusterIP<br>  clusterIP: None<br>  ports:<br>  - name: peer<br>    port: 27017<br>  selector:<br>    app: notification-mongodb</pre><p>Now, we need to update the MongoDB URL used by the Notification application. In the filek8s/notification/notification-deployment.yml find mongodb://notification-mongodb-0.notification-mongodb.default:27017 and replace it with mongodb://notification-mongodb.default.svc.cluster.local:27017</p><p>Now we are ready.</p><p>Let us build and push the docker images for our application. Follow the instructions above and build docker images in each of the application folders and then tag and push the images to your Docker hub account.</p><h4>Preparing AKS Cluster</h4><p>Now that our applications are built and pushed its time for us to deploy them to AKS. But before that let’s make sure we have all the prerequisites ready. You will need the below tools.</p><ol><li><a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/">kubectl</a>: The command line tool to interact with Kubernetes. Install and configure it.</li><li><a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">Azure CLI</a>: The command line tool to interact with Azure. Install and log in with your Azure account(You can create a <a href="https://azure.microsoft.com/en-us/free/">free account</a> if you don&#39;t have one already).</li></ol><p>Once the tools are ready let us prepare our Kubernetes cluster.</p><p>First, let us create a resource group. Run the below command. This will create a resource group named <strong>eCommerceCluster</strong> in US east location(You can use other <a href="https://azure.microsoft.com/en-us/global-infrastructure/regions/">Azure regions</a> as well).</p><pre>$ az group create --name <strong>eCommerceCluster</strong> --location <strong>eastus</strong></pre><p>Now let us create an AKS cluster on the resource group we just created. Run the below command to create a cluster named eCommerceCluster with two nodes(We would need some room to run all those containers). It also enables the Azure monitor on the cluster through the add-on specified.</p><pre>$ az aks create --resource-group <strong>eCommerceCluster</strong> --name <strong>eCommerceCluster</strong> --node-count <strong>2</strong> --enable-addons <strong>monitoring</strong> --generate-ssh-keys</pre><p>This would take several minutes to complete hence be patient and have a coffee :)</p><p>Did I emphasize on <strong>several minutes</strong>?</p><p>Once it&#39;s done you should see the cluster information printed out as JSON.</p><p>Now, let us configure <strong>kubectl</strong> to connect to the AKS cluster we just created. This can be done automatically using the Azure CLI by running the below handy command.</p><p>Note: Some Azure CLI commands might take a while to execute, especially if you are on a slow network, sometimes if the below commands seem stalled or if it is timed out, kill it and retry again.</p><pre>$ az aks get-credentials --resource-group <strong>eCommerceCluster</strong> --name <strong>eCommerceCluster</strong></pre><p>Verify that we are able to connect to the cluster by running kubectl get nodes</p><pre>$ kubectl get nodes<br>NAME                       STATUS    ROLES     AGE       VERSION<br>aks-nodepool1-34429729-0   Ready     agent     22m       v1.9.9<br>aks-nodepool1-34429729-1   Ready     agent     22m       v1.9.9</pre><h4>Deploying the application to AKS</h4><p>Now that our cluster is ready, let us deploy our microservice stack to this cluster.</p><p>We can deploy our application using the kubectl apply command for this we have to navigate to the k8s folder we created earlier and run the below commands in the same order</p><pre>$ kubectl apply -f <strong>registry</strong></pre><pre>$ kubectl apply -f <strong>invoice</strong></pre><pre>$ kubectl apply -f <strong>notification</strong></pre><pre>$ kubectl apply -f <strong>store</strong></pre><p>Or you could also just run the handy kubectl-apply.sh script generated which runs the above.</p><p>So we are deploying the JHipster Registry first as it is required for other services, followed by the microservices and finally our gateway(store).</p><p>If you get a timeout during any of these, as I did, just try the command again.</p><p>Though the services get created fast, the actual applications might not be up and running yet, give the entire thing a minute or two to start.</p><p>Now run kubectl get pods to see the status of our containers.</p><pre>$ kubectl get pods -w</pre><pre>NAME                                    READY  STATUS <br>invoice-5ffb46d944-h8x42                1/1    Running<br>invoice-mysql-66bc4b7874-p7ghk          1/1    Running<br>jhipster-registry-0                     1/1    Running<br>jhipster-registry-1                     1/1    Running<br>notification-76847b7667-d7xjb           1/1    Running<br>notification-mongodb-6db986b556-8bw8z   1/1    Running<br>store-8dc5cd6f7-s2dpx                   1/1    Running<br>store-mysql-779d66685d-tmkqd            1/1    Running</pre><p>Note: I have removed some info for brevity in the above output.</p><p>Wait until all the containers are in <strong>Running</strong> status. Once the containers are running we can run the kubectl get service command to get the external IP for the application.</p><pre>$ kubectl get service <strong>store</strong></pre><pre>NAME   TYPE         CLUSTER-IP    EXTERNAL-IP    PORT(S)         AGE<br>store  LoadBalancer 10.0.189.145  <strong>40.117.140.228</strong> <strong>8080</strong>:30143/TCP  18m</pre><p>In this case, the external IP for our gateway application is <strong>40.117.140.228</strong> running on port <strong>8080</strong>. Let us open it up in a web browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OQSuDw4u-CHGdkl0VR_DIw.png" /><figcaption>The Gateway application login page</figcaption></figure><p>The JHipster registry is deployed as a headless service by default. If we need to access the registry we need to create a secondary service with a Load Balancer. Run the below command to expose the second service.</p><pre>$ kubectl expose service jhipster-registry --type=<strong>LoadBalancer</strong> --name=<strong>exposed-registry</strong></pre><p>Now run the kubectl get service command to get the IP.</p><pre>$ kubectl get service <strong>exposed-registry</strong></pre><pre>NAME             TYPE         CLUSTER-IP   EXTERNAL-IP    PORT(S)<br>exposed-registry LoadBalancer 10.0.107.121 <strong>104.211.15.142 8761</strong>:32628/TCP</pre><p>Visit the URL in a browser to see the registry in action</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tWbLvvpXCF9kHPmEadyMKQ.png" /><figcaption>JHipster Registry home page</figcaption></figure><p>We can now scale any of our services by simply running kubectl scale command. For example, let us scale our Invoice service.</p><pre>$ kubectl scale --replicas=<strong>2</strong> deployment/<strong>invoice</strong></pre><p>Now we can visit the <strong>Eureka -&gt; Instances</strong> on our Registry and see that the Invoice service has two instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YGhPu44fNsApmKZYXQAaqQ.png" /><figcaption>JHipster Registry instances page</figcaption></figure><p>Running kubectl get pods will also show you the new instance.</p><pre>$ kubectl get pods<br> <br>NAME                                  READY  STATUS   AGE<br><strong>invoice-5ffb46d944-g8j6j</strong>              1/1    Running  <strong>4m</strong><br>invoice-5ffb46d944-h8x42              1/1    Running  2h<br>invoice-mysql-66bc4b7874-p7ghk        1/1    Running  2h<br>jhipster-registry-0                   1/1    Running  2h<br>jhipster-registry-1                   1/1    Running  2h<br>notification-76847b7667-d7xjb         1/1    Running  2h<br>notification-mongodb-6db986b556-8bw8z 1/1    Running  2h<br>store-8dc5cd6f7-s2dpx                 1/1    Running  2h<br>store-mysql-779d66685d-tmkqd          1/1    Running  2h</pre><p>That is it, we have successfully got our application deployed to AKS and scaled our service on demand.</p><h4>Cleanup</h4><p>Once you are done its always a good idea to clean up especially since we don&#39;t want to keep unnecessary resources that might eat up our free credits on Azure.</p><p>Let us delete the cluster from AKS and related resources created by deleting the entire resource group.</p><pre>$ az group delete --name <strong>eCommerceCluster</strong> --yes --no-wait</pre><p>Cluster related activities like creation/update/deletion could take several minutes on AKS so we have to be patient again here.</p><h4>Conclusion</h4><p>Kubernetes is definitely the best way to deploy microservice applications to production but creating and managing Kubernetes clusters itself is not an easy task, but Kubernetes services like <strong>GKE</strong> and <strong>AKS</strong> makes it a cakewalk. In my personal experience, the Kubernetes service from Google(GKE) and Azure(AKS) are by far the best in terms of ease of use and available tooling. These services provide very handy command line tools which work nicely together with <strong>kubectl</strong> to provide a very nice experience. They also have nice UI portals if you are not a fan of the CLI.</p><p>JHipster provides a great Kubernetes setup to start with which you can further tweak as per your needs and platform. Once the <a href="https://github.com/jhipster/generator-jhipster/issues/8422">issues</a> with MongoDB clustering and Elastic stack are sorted out, I’ll update the post to include MongoDB clustering and JHipster Console monitoring with Zipkin tracing. So don’t forget to check back.</p><p>In upcoming posts, we will look at more services like GKE(Google), EKS(Amazon) and Openshift(RedHat)</p><p>To learn more about JHipster, check out my book “<em>Full Stack Development with JHipster</em>” on <a href="https://www.amazon.com/Stack-Development-JHipster-Deepu-Sasidharan/dp/178847631X">Amazon</a> and <a href="https://www.packtpub.com/application-development/full-stack-development-jhipster">Packt</a>.</p><p>If you like JHipster don’t forget to give it a star on <a href="https://github.com/jhipster/generator-jhipster">Github</a>.</p><p>If you like this article, please leave some claps (Did you know that you can clap multiple times? :P )</p><p>You can follow me on <a href="https://twitter.com/deepu105">Twitter</a> and <a href="https://www.linkedin.com/in/deepu05/">LinkedIn</a>.</p><p>My other related posts:</p><ol><li><a href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">Create full Microservice stack using JHipster Domain Language under 30 minutes</a></li><li><a href="https://medium.com/@deepu105/jhipster-microservices-with-istio-service-mesh-on-kubernetes-a7d0158ba9a3">JHipster microservices with Istio service mesh on Kubernetes</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb46991746ba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jhipster/deploying-jhipster-microservices-on-azure-kubernetes-service-aks-fb46991746ba">Deploying JHipster Microservices on Azure Kubernetes Service (AKS)</a> was originally published in <a href="https://medium.com/jhipster">JHipster</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>