<?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 Teja Swaroop Mylavarapu on Medium]]></title>
        <description><![CDATA[Stories by Teja Swaroop Mylavarapu on Medium]]></description>
        <link>https://medium.com/@tejaswaroopmylavarapu?source=rss-248b5a922263------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*b_aosjRWT-bHdmgHLghpXw@2x.jpeg</url>
            <title>Stories by Teja Swaroop Mylavarapu on Medium</title>
            <link>https://medium.com/@tejaswaroopmylavarapu?source=rss-248b5a922263------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 00:13:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tejaswaroopmylavarapu/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[GenAI — How to create a RAG and interact with LLM]]></title>
            <link>https://levelup.gitconnected.com/genai-how-to-create-a-rag-and-interact-with-llm-59cda1e3e2bc?source=rss-248b5a922263------2</link>
            <guid isPermaLink="false">https://medium.com/p/59cda1e3e2bc</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[embedding-model]]></category>
            <category><![CDATA[prompt-engineering]]></category>
            <category><![CDATA[rags]]></category>
            <dc:creator><![CDATA[Teja Swaroop Mylavarapu]]></dc:creator>
            <pubDate>Sat, 28 Sep 2024 23:50:07 GMT</pubDate>
            <atom:updated>2024-09-29T14:20:59.006Z</atom:updated>
            <content:encoded><![CDATA[<h3>GenAI — How to create a RAG and interact with LLM through Prompt Engineering</h3><p>We all know how disruptive LLMs are and how powerful their knowledge is. If LLMs are the brains trained over the internet, how useful is that brain if it cannot answer questions on the enterprise data we possess ?</p><p>Well, not very much.</p><p>We need the brains of LLMs to train and scrape on <strong><em>our data source</em></strong> and answer complicated queries on our data. That’s where the concept of RAG which is Retrieval Augmented Generation kicks in &amp; does the heavy lifting of sourcing your LLM with different types of external Data Sources and answer queries effectively</p><p>Today, in this article we are going to accomplish the following:</p><ol><li>Import Statements and OpenAI Key</li><li>Create some mock JSON document — Data Source on which LLM needs to be trained.</li><li>Convert the document data into Embeddings</li><li>Create Vectore Stores using FAISS</li><li>Setup Vector Store Retriever</li><li>Setup the Large Language Model (LLM) — OpenAI</li><li>Setup Retrieval Chain and query with Prompt Engineering for Answers.</li></ol><p><strong><em>The following code blocks can be run via jupyter notebook for easier execution</em></strong></p><blockquote>Import Statements and OpenAI Key</blockquote><pre>from langchain.vectorstores import FAISS<br>from langchain.embeddings import OpenAIEmbeddings<br>from langchain.llms import OpenAI<br>from langchain.chains import RetrievalQA<br>from langchain.prompts import PromptTemplate<br>from langchain.schema import Document<br><br>from langchain_openai import ChatOpenAI<br>import os<br><br>os.environ[&quot;OPENAI_API_KEY&quot;] = &quot;&lt;Register with OpenAI and obtain the Key&gt;&quot;</pre><blockquote>Create some mock JSON document — Data Source on which LLM needs to be trained</blockquote><pre>docs = [<br>    Document(page_content=&quot;Medium is a social publishing platform that allows users to write, publish, and share their stories with a broad audience&quot;),<br>    Document(page_content=&quot;Medium is open to anyone, so it&#39;s a good option for beginners.&quot;),<br>    Document(page_content=&quot;Medium has a wide range of content, including stories, ideas, and perspectives on topics like mental health, social media, and world affairs&quot;)<br>]</pre><p>The above data is some Wiki data on “Medium.com” and what Medium as a blog platform is about. LLM will eventually be queried on this particular set of data.</p><blockquote>Convert the document data into Embeddings</blockquote><pre>embedding_model = OpenAIEmbeddings(model=&quot;text-embedding-ada-002&quot;) </pre><p>We are using OpenAI and leveraging the most popular “text-embedding-ada-002” as the embedding model considering the textual JSON data that we sourced.</p><blockquote>Create Vector Stores</blockquote><pre>vector_store = FAISS.from_documents(docs, embedding_model)</pre><p>We convert the Embeddings into Vectors for effective querying, similarity search and semantic matching. It helps in dimensinality reduction in large datasets. It also scales for performance and memory optimization.</p><p>If the data is fixed, we can convert the embeddings into vectors once and continously query as a separate function and separate the Vectors creation and querying as 2 spearate entities.</p><p>If dealing with continous data, we can continously convert the embeddings into vectors and append to the existing vectors and store them and query on them continously.</p><blockquote>Setup Vector Store Retriever</blockquote><pre>retriever = vector_store.as_retriever()</pre><p>Create a Vector store Retriever Object for querying with Retrieval chain through LLM</p><blockquote>Setup the Large Language Model (LLM) — OpenAI</blockquote><p>Initiate the llm Object to which we need to connect, talk and train to.</p><p>We are using GPT-4 as our LLM. As we are using LangChain, this can be replaced with any LLM of your choice.</p><pre>llm_setup = ChatOpenAI(model=&quot;gpt-4&quot;)</pre><blockquote>Retrieval Chain</blockquote><pre>qa_chain = RetrievalQA.from_chain_type(<br>        llm=llm_setup,<br>        chain_type=&quot;stuff&quot;,  <br>        retriever=retriever<br>    )</pre><p>Setup the Retrieval Chain where you pass in the LLM and the Vector Store Retriever which has the JSON data in the form of Vectors passed into it. The Chain is what we query the LLM through Prompt Engineering</p><blockquote>Prompt Engineering:</blockquote><pre>query = &quot;What content does Medium have?&quot;</pre><p>A simple query that we want to query on the JSON data that we fed into the Chain</p><blockquote>Query the LLM:</blockquote><pre>llm_response = qa_chain.run(query)<br>print(llm_response)</pre><blockquote>Expected Answer:</blockquote><pre>Medium has a wide range of content, including stories, ideas, and perspectives on topics like mental health, social media, and world affairs. It&#39;s a platform where users can write, publish, and share their stories with a broad audience. Since it&#39;s open to anyone, it can be a good option for beginners to start sharing their work.</pre><p>qa_chain is th<strong>e pipeline</strong> that handles the querying and answering process. It lets the LLM understand our query by converting our query into a query vector, then matches for similarity and answers through the FAISS vector store and finds the most similar match corresponding to the questions and executes the response.</p><p>There are other parameters such as temparature which can be passed through the LangChain object to let the LLM be more creative or less creative.</p><p>By leveraging the concept of RAG and feeding the LLM with the right source of data reduces the concept of LLM Hallucination and makes the LLM more accountable while still be creative in answering queries on the data that WE want and enhance our Productivity.</p><p>The above example is a simple step by step approach on how to setup LLM with RAG and should be leveraged by Engineers who wants to feed their curated data to LLM and obtain answers to enhance their Tech Productivity and also enhance their Product capabilities by sourcing on their company’s data.</p><p>I hope this article of mine has thrown some light in understanding the RAG Architecture and getting started with querying LLM with external data sources.</p><p>If you like this article, please do Clap hands at the bottom of the page. It encourages me to write more…!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59cda1e3e2bc" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/genai-how-to-create-a-rag-and-interact-with-llm-59cda1e3e2bc">GenAI — How to create a RAG and interact with LLM</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started on Performance Testing — Stress vs Load vs Enduranc]]></title>
            <link>https://medium.com/swlh/getting-started-on-performance-testing-stress-vs-load-vs-enduranc-8c8bcb54d0d4?source=rss-248b5a922263------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c8bcb54d0d4</guid>
            <category><![CDATA[endurance-testing]]></category>
            <category><![CDATA[performance-testing]]></category>
            <category><![CDATA[autoscaling]]></category>
            <category><![CDATA[stress-testing]]></category>
            <category><![CDATA[load-testing]]></category>
            <dc:creator><![CDATA[Teja Swaroop Mylavarapu]]></dc:creator>
            <pubDate>Sat, 27 Jul 2024 15:48:14 GMT</pubDate>
            <atom:updated>2024-07-27T20:50:35.708Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting started on Performance Testing — Stress vs Load vs Endurance</h3><h3><strong>What is Performance Testing?</strong></h3><p>Performance testing is a testing mechanism which tests for scalability of your Application. It tests for your Application’s ability to react, its behavior during an influx of incoming requests, responsiveness, speed and endurance.</p><p>Perf testing decides if your Application is able meet the load for the incoming high traffic. It also tests on how your Application scales up and meets the demand for the high load and observes how the Application cools down on low load.</p><p>There are various types of Performance tests, we will be discussing the top 3 types of testing which are mandatory for an Application in this blog:</p><ol><li>Load Testing</li><li>Stress Testing</li><li>Endurance Testing/Soak Testing</li></ol><p>Let’s evaluate each types of Performance Testing in detail and also understand the reasoning behind why we need them.</p><p>The key questions to ask during this process are:</p><ol><li>How is our Application deployed that we want to test against — Is it on localhost, on a lower non-prod environment.</li><li>What sort of Infrastructure is our Application hosted on — Is it hosted on Cloud Components such as EC2, Lambda, Fargate and are we using Docker containers.</li><li>What are the CPU and Memory Configurations that were configured while deploying the Application — If we are on Docker, what is the CPU and Memory that is configured, how many containers of our Application are deployed on the Infrastructure.</li></ol><h4><strong>Load Testing:</strong></h4><blockquote><em>What is Load Testing?</em></blockquote><p>Load testing is a specialized form of performance testing that assesses how a system performs under a predetermined expected load. Its main goal is to evaluate the application’s performance during both normal and peak usage conditions.</p><p>We know the number of users to anticipate in this testing and run our Application/Infrastructure against this expected load to test how our APplication responds to this level of Load when encountered in Production.</p><blockquote>Time to Run:</blockquote><p>Minimum of 20 minutes to a maximum of 2 hours.</p><blockquote><em>When to Perform:</em></blockquote><p>Usually performed during the development and testing phases of the software lifecycle and before major releases.</p><blockquote>What to validate:</blockquote><p>i. We want to test if the Application when hosted in Production can sustain the load which it is desired to.</p><p>ii. How much of Memory and CPU is the Application consuming or spiking during this run. Do they need any tunings or config modifications to support the baseline TPS of 1x load of your Application.</p><h4>Stress Testing:</h4><blockquote><em>What is Stress Testing?</em></blockquote><p>Stress testing is performed to assesses how a system performs under extreme conditions that exceed its normal load capacity. It is used to analyze how the Application withstands sudden spikes of incoming traffic.It is also performed to identify the system’s breaking point and analyze its behavior when faced excessive load or limited resources.</p><p>We test the Application with 1x, 2x and 5x loads in shorter durations of time.</p><blockquote>Time to Run:</blockquote><p>Minimum of 30 minutes to a maximum of 3 hours.</p><p>For 30 minutes test: Have 1x load for 10 minutes, 2x load for 10 minutes and 5x load for 10 minutes.</p><p>For 3 hour test: Have 1x load for 1 hour, 2x load for 1 hourand 5x load for 1 hour.</p><p>We can also include 3x and 4x loads and also adjust the time accordingly.</p><blockquote><em>When to Perform:</em></blockquote><p>Usually conducted after load testing, during the later stages of the software development lifecycle and before the Production release to test Auto scaling abilities.</p><blockquote>What to validate:</blockquote><p>i. We want to test if the Application when hosted in Production can sustain the load when sudden spikes of traffic comes in.</p><p>ii. Test for Auto scaling abilities: Validate if the Application has auto-scaled itself during the 2x and above loads. If the Application does not Auto scale either Horizontally or Vertically, then the memory and CPU configurations need to be adjusted to Auto scale.</p><p>To know more about Horizontal and Vertical Autoscaling and to fine tune the configurations — Read my <a href="https://medium.com/swlh/how-to-autoscale-your-application-with-aws-ec2-instances-and-docker-containers-975ab1263454">Blog on Auto Scaling</a></p><p>iii. Validate the Alarms if they are getting triggered during this High Scaling scenarios. If there are any 5xx Errors that are getting triggered during these events and fine tune the Thresholds of the Alarms during this process as desired.</p><h4>Endurance Testing:</h4><blockquote><em>What is Endurance Testing?</em></blockquote><p>A type of performance testing that examines how a system operates under a continuous load for an extended duration. We test the System for longer periods of time with a minimum load of 1x and validate its responsiveness. The main goal is to evaluate the system’s stability, reliability, and performance over time and ensure its endurance.</p><blockquote>Time to Run:</blockquote><p>Minimum of 8 hours to a maximum of 3 days on 1x load.</p><blockquote><em>When to Perform:</em></blockquote><p>This test is usually conducted after Stress and Load Testing and before any major release.</p><blockquote>What to validate:</blockquote><p>i. We want to test if the Application when hosted in Production can sustain the 1x load which it is desired to.</p><p>ii. How much of Memory and CPU is the Application consuming or spiking during this run. Do they need any tunings or config modifications to support the baseline TPS of 1x load of your Application.</p><p>iii. Leaks: Are there any Memory leaks in your Application which is constantly draining your Application.</p><p>iv. Performance: How is the Throughput, Latency and responsiveness of the Applications for this longer duration</p><p>v. Resource Utilizations and its side affects.</p><p><strong><em>Tools leveraged to conduct Performance testing:</em></strong></p><p>a. Apache JMeter</p><p>b. LoadRunner</p><p>c. NeoLoad</p><p>d. Gatling</p><p>e. K6</p><p>…. and many more.</p><blockquote>In the discussion below, we will be using Apache JMeter to understand the configurations.</blockquote><h3>JMeter Configurations:</h3><blockquote>Thread Group Configuration:</blockquote><p>How to select Thread Group in JMeter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*SEdACd_WLZdgzW1yba1AFQ.png" /></figure><p>Configuration of Threads:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zm_RCOrfce5ze1wNdKxGiw.png" /></figure><p>This is used to configure the number of Threads. Ramp up time, the duration of the test and etc.</p><p>To set the load to 1x, 2x and 5x, the number of threads needs to be tweaked depending on how your Application is hosted.</p><p>For Stress testing, ram up time needs to be adjusted along with Threads to spike up traffic at certain intervals of time.</p><p>The duration indicates the amount of time a test has to run.</p><blockquote>HTTP Request Configuration:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*beJU9jJNvIhEEDxvr8TBVA.png" /></figure><p>The above image showshow to configure a simple GET endpoint “<strong><em>HTTP Request”</em></strong> with JMeter. It has the options to configure Protocol, Server, Port Number, HTTP Request type, endpoint path and also body in case of POST requests.</p><p>How to select HTTP Request in JMeter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*ibbt0Mi4PPnYzGx_DYsbvA.png" /></figure><blockquote>Summary and Aggregate Report Configurations:</blockquote><p><strong>Summary Report</strong> is a listener that provides a concise overview of the performance test results. It aggregates the data collected during a test execution and presents it in a tabular format, summarizing key performance metrics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*vyG2p6zn7Qigu-OsCJiNvA.png" /></figure><p>After the test is completed, Summary Report provides the number of Samples run, the TPS (Throughput) the test completed with, error thresholds, Latency and other results.</p><p>You can export the results from the Summary Report to a CSV or XML file for further analysis or reporting.</p><p>Overall, Performance testing is useful to ensure scalability of the Application, withstand spikes of traffic, memory leaks, identify bottlenecks, ensure reliability, cost savings by fine tuning the Memory and CPU configs and finally be compliant with the benchmark standards.</p><p>For an Application to get into Production, performance testing is extremely crucial and is considered one of the important steps of testing and is stringly advised to perform the above steps before deploying an Application into the Production environment.</p><p>I hope this article of mine has thrown some light in understanding the types and metrics of Performance testing and changed your perspective towards Perf testing.</p><p>If you like this article, please do Clap hands at the bottom of the page. It encourages me to write more…!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c8bcb54d0d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/getting-started-on-performance-testing-stress-vs-load-vs-enduranc-8c8bcb54d0d4">Getting started on Performance Testing — Stress vs Load vs Enduranc</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started in GraphQL With Spring Boot in Java]]></title>
            <link>https://medium.com/swlh/how-to-write-a-simple-graphql-application-using-spring-boot-in-java-a8232a0decd5?source=rss-248b5a922263------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8232a0decd5</guid>
            <category><![CDATA[graphql-java]]></category>
            <category><![CDATA[graphql-schema]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[spring-boot-graphql]]></category>
            <category><![CDATA[graphql-server]]></category>
            <dc:creator><![CDATA[Teja Swaroop Mylavarapu]]></dc:creator>
            <pubDate>Sun, 17 Jan 2021 17:43:03 GMT</pubDate>
            <atom:updated>2021-02-20T21:03:36.304Z</atom:updated>
            <content:encoded><![CDATA[<p>GraphQL — <strong>GraphQL</strong> is a query language for APIs and a runtime for fulfilling those queries with your existing data.</p><p>This is what the standard definition of GraphQL is. I am going to break down the concept of GraphQL with a more hands on approach as described below.</p><blockquote>In this blog, I am going to talk about:</blockquote><ol><li>What exactly is GraphQL?</li><li>Why do we need GraphQL and what are the advantages of using GraphQL.</li><li>Setup the Java Spring Boot Micro Service on your local using Spring Initializr.</li><li>Write a simple GraphQL Spring Boot application in Java.</li><li>Build a GraphQL request via Postman and query our Application.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0tyIH4NmwDkEiUm24Vw9w.jpeg" /></figure><blockquote>1. What exactly is GraphQL?</blockquote><p>GraphQL is a query language and a standard for APIs that describes how to ask for data and load data from a server to a client.</p><p>It lets the client ask what data they want dynamically, not the usual standard ‘REST’ response.It is a more expressive standard that lets the Producer properly aggregate data on demand and serve that data on the fly.</p><p>The way Cloud Computing has revolutionized the mindset of ‘Pay as you use’ model, GraphQL lets users request response as they go.</p><blockquote>2. Why do we need GraphQL and what are the advantages of using GraphQL.</blockquote><blockquote>Problem:</blockquote><p>Imagine a scenario, where you have a Mobile and Desktop User Interface. In today’s world, you build an endpoint for both of them and retrieve the data from a standard REST endpoint.</p><p>For example, let us assume that our API returns back with a JSON comprising of 50 fields.</p><p>For Desktops, this is agreeable as the real estate on the desktop is much bigger than Mobile and all the variables and data can be accommodated in a succinct manner.</p><p>However, for Mobile, with lack of real estate, we cannot accommodate all the variables and we do not require all the 50 variables returned by our Micro Service.</p><blockquote>Solution:</blockquote><p>The only solution we have today is to build out another endpoint for Mobile and serve the data. This is an overhead as both the endpoints deal with the similar Repository.</p><p>Enter GraphQL, which lets the user request the data as they want in the form of Queries (in Payload). The user can request what they want, GraphQL fetches only that data what the user wants and eliminates the unnecessary data transmission over the network.</p><p>This is just one simple problem which I have addressed and there are many more problems whichGraphQL can address.</p><p>There are many advantages of using GraphQL. Some of them are:</p><p>a. No Over-fetching and Under-fetching of Data — Subscribe for what you want</p><p>b. Reduces Network Latency</p><p>c. Supports Dynamic API Responses</p><p>d. Single Endpoint</p><p>e. Reducing the concept of Versioning the APIs</p><p>f. No more Strict Handshake between developers — De Coupling</p><p>and etc. The list does not stop here.</p><p>So, let’s quickly jump into the implementation part of how to implement a GraphQL layer using Spring Boot in Java.</p><blockquote>3. Setup the Java Spring Boot Micro Service on your local using Spring Initializr.</blockquote><p>Go to the Spring Initializr URL, where you can create the basic Spring Boot Project located at:</p><p><a href="https://start.spring.io/">Spring Initializr</a></p><p>Just give the appropriate GroupId and the Artifact Id and add some basic dependencies to kick start your Spring Boot Application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QIvXlfthtzp3DjDBba8oMg.png" /></figure><p>Once you have the Project downloaded, open it in your favorite editor and just modify your application.properties file to run this project on a local port and the context path. I am using IntelliJ for this demo.</p><blockquote><em>server.servlet.context-path=/graphql-learnings</em></blockquote><blockquote><em>server.port = 6060</em></blockquote><p>Your Application now runs on Port 6060. I used port 6060 to keep it unique and avoid port clashes. You are free to use any port you please.</p><p>You can further add security to your Application by creating and adding a self signed certificate and add the ‘https’ layer by following my other blog here:</p><p><a href="https://medium.com/swlh/create-a-self-signed-certificate-keystore-using-keytool-and-host-your-spring-boot-application-on-d29fe3a15043">Create a Self Signed Certificate (Keystore) using keytool and host your Spring Boot Application on…</a></p><p><strong><em>I am not going to to that for this below GraphQL Application.</em></strong></p><blockquote>4. Write a simple GraphQL Spring Boot application in Java.</blockquote><p>GraphQL as discussed above comprises of Schemas, queries, mutations and etc. Let’s go ahead and write a schema file with a simple query returning an object.</p><blockquote>Step i: Add the GraphQL dependencies</blockquote><p>Go to pom.xml file and add the appropriate GraphQL dependencies as show below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_1c0MHhtYt8xtS4yUDK3pw.png" /></figure><blockquote>Step ii: Create the Schema file:</blockquote><p>Go to src/man/resources and create a schema.graphql file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J9Y-vOWxTFCIy43O_UxlOg.png" /></figure><p>We have written a simple query for stocks where we return a Mapper Object with all the above detailed field variables. The type StockMapper is the superset object that our Application returns.</p><p>The User, can cherry pick the fields he/she wants and get back the desired fields as requested upon. They get what they want, but not what we return and thus more power to them.</p><blockquote>Step iii: Add the standard GraphQL Layer</blockquote><p>Now, let’s go ahead and introduce the GraphQL Layer into our code by creating a package and add a Service layer as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ZQe8zKQgk5ApymegWymnw.png" /></figure><p>Let us talk about the above code line by line for a good understanding as this is wiring is very important.</p><p>Line 27: The main GraphQL Object which holds all the data of the schema and the Runtime wiring for our Application. This object is returned on Line 58 to the controller layer where we expose the GraphQL endpoint in the coming sections.</p><p>Line 30: The repository layer which we will be building next which fetches the data that we want/ the user wants.</p><p>Line 33: This is required to load the schema file present under the classpath inside the resources folder to serve GraphQL the schema we desire.</p><p>Line 35: The below method is loaded during runtime as soon as the Application starts to serve the data.</p><p>Line 42: Used for compiling a graphQL schema definition file with SchemaParsers.</p><p><strong>Line 51: Builds the runtime wiring object for GraphQL. Here is where we map the schema in the schema file to the repository layer. In the schema.graphql file on Line 6, we had stocks as the query object coming in from the user and the user would send out the desired query. We need to map this query to our Repository layer and serve this data back to the user. Line 54 does exactly this. It maps the incoming request from the client (user query) to our backend Repo layer and does the magic.</strong></p><blockquote>Step iv: Build the Repository Layer:</blockquote><p>After the wiring of the Service, we need to build a Repo Layer to get the data. This part is going to be very simple as I leave it to the developer to build this layer as per their own use case.</p><p>Data can be fetched from many sources not limiting to:</p><p>a. Database</p><p>b. Cache Services</p><p>c. Another downstream API call</p><p>d. Kafka Consumer Services</p><p>and etc. In this blog, I shall be constructing a simple Object for Demo purposes.</p><blockquote>Create a model package and create a class called StockDetails.java which has all the required fields.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rI-2WtA4TS_gyBJI_tcsIw.png" /></figure><blockquote>Create a Repository Layer as below and return the details as an ArrayList</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yPp8kRXEwZLsiExg-sbKqg.png" /></figure><p>You can build this Object as desired by getting the data from any other source.</p><blockquote>Step v: Build the Controller layer and expose a GraphQL endpoint to the user</blockquote><p>Let us build a controller layer and expose a POST endpoint to the end user and enable the feature to let the user query our Application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BR4tKkPsf7bEDFXegUrLYA.png" /></figure><p>The above code pretty self explanatory as we have created an Autowired Object pointing to the Service layer which triggers the graphQL Layer. Next, there is a new POST endpoint which has been created and which accepts String as payload which the user sends as Query. The String is sent out to the GraphQL Service Layer and the data is obtained back and parsed back to the user in the form of String.</p><p>With this, we have completed the coding part of our Application and its time to start the Application which should start on port 6060 as mentioned in our previous steps on localhost.</p><blockquote>5.Build a GraphQL request via Postman and query our Application.</blockquote><p>Build a GraphQL Request via postman or via Curl command on to our application with all the Payload Parameters sent as query as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5oQcIiXxW0Mjkpo7tAFfEQ.png" /></figure><p>Voila..!!! There you go. Once the user requests what they want in the form of GraphQL query, they get back the data as desired.</p><p>Now, let’s leverage the power of GraphQL and query only a small subset of fields which we are interested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvQ59ppIzWwjVhRkcFadBA.png" /></figure><p>If we can observe the Request and Response in the above diagram, we can see that we have requested only 3 fields from our GraphQL Application and we got back only those 3 fields which we requested. Even though our Applications can respond back with a whole lot of other fields, we can leverage GraphQL and get back what WE want not what the Application can return.</p><p>This, in my opinion is a game changer. As we clearly observe on the ‘Time’ and the ‘Size’ fields on Postman, we can clearly see the difference in those fields taken for heavy load vs the normal load which we requested.</p><p>Depending on the use case, users can query the data how much ever they want and reduce the latency and also the Network bandwidth over the network as less data will be traversed.</p><p>I hope this article of mine has shed some light on how to connect to create a simple GraphQL Application on Spring Boot using Java. Happy Coding…!!</p><p>If you have liked what you read, Please Clap hands below as this encourages me to write more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8232a0decd5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-write-a-simple-graphql-application-using-spring-boot-in-java-a8232a0decd5">Getting Started in GraphQL With Spring Boot in Java</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connect your Micro Service (Spring Boot Application) to AWS DynamoDB]]></title>
            <link>https://levelup.gitconnected.com/connect-your-micro-service-spring-boot-application-to-aws-dynamodb-e86a430d418e?source=rss-248b5a922263------2</link>
            <guid isPermaLink="false">https://medium.com/p/e86a430d418e</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[dynamodb-client]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[nosql]]></category>
            <dc:creator><![CDATA[Teja Swaroop Mylavarapu]]></dc:creator>
            <pubDate>Sun, 02 Aug 2020 18:00:39 GMT</pubDate>
            <atom:updated>2020-08-14T11:38:17.997Z</atom:updated>
            <content:encoded><![CDATA[<p>Spring Boot + DynmoDB is a good combination depending on the use case, with one being the de facto framework for Java and the other being the Next Gen NoSQL database in the AWS world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*xJH0mo_Ms81mSRU3sgVVSA.png" /></figure><p>In this article, I am going to talk about:</p><ol><li>Addressing Prerequisites — Setup your AWS Account, CLI on your Terminal.</li><li>Create a DynamoDB Table on AWS Console and add a sample value.</li><li>Setup the Java Spring Boot Micro Service on your local using Spring Initializr.</li><li>Integrate the DynamoDB code into your Java Application using AWS SDK and successfully read the sample value.</li></ol><blockquote><strong>1. Addressing Prerequisites — Setup your AWS Account, CLI on your Terminal.</strong></blockquote><blockquote>Let’s first address the pre-requisites</blockquote><ol><li>Get the Access Key ID and Secret Access Key from AWS Account</li><li>Install AWS CLI on your local machine</li><li>Configure AWS credentials for the AWS Account on your machine</li></ol><blockquote><em>Get the Access Key ID and Secret Access Key from AWS Account</em></blockquote><p>Go to <a href="https://aws.amazon.com/console/">https://aws.amazon.com/console</a>/ and login to the AWS Console. Navigate to IAM section-&gt;Dashboard-&gt;Manage Security Credentials → AccessKeys Tab and extract your Access Key ID and Secret Access Key.</p><p>Go ahead and Create on if you don’t have one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*F75R6n10yirnZY-8QZl7EA.png" /></figure><blockquote><em>Install AWS CLI on your local machine</em></blockquote><p>After jotting down the keys, let’s install AWS CLI v2 on your system. If you already have this configured, please proceed to Step 3 where we create the AWS Infra.</p><p>Install AWS CLI by following the commands mentioned in the AWS documentation.</p><p><a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html">Installing, updating, and uninstalling the AWS CLI version 2 on macOS</a></p><p>After installing AWS CLI, go to your mac Terminal and type in aws and that should list something like the image below. This confirms and validates that AWS CLI has been successfully configured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*bke6pFw5DKb7TSaMtsBptA.png" /></figure><blockquote><em>Configure AWS credentials for the AWS Account on your machine</em></blockquote><p>Now, time to map your AWS Credentials on your local machine. We need to configure the Access Key ID and Secret Access Key on your machine so that you can connect to yourAWS Account from your machine and create and disrupt the Infra using AWS CLI.</p><p>aws configure should do the trick and ask for the Credentials, region and the output format. You might want to configure it as the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*PGrbPSIuq7o-0ACt3EJtEg.png" /></figure><p>We can validate this by going to your ~/.aws/credentials</p><p>This file validates the Credentials we have just added in the terminal and displays the keys. With this step finished, we now have access to the AWS Account from our machine through AWS CLI. Great We are done with the setup…!!!</p><blockquote>2. Create a DynamoDB Table on AWS Console and add a sample value.</blockquote><p>Go to the AWS Console and type in DynamoDB and land on the DynamoDB Page and click on “Create Table”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xIEG6cfAz0B5MgEoXbk8qQ.png" /></figure><p>Create a new table called “stocks” and add the “stock_id” as a Primary Key and go ahead and create the new table. It might take a moment to create one. We will not deep dive into Secondary Indexes and Sort Keys in this article as we are just covering the basics on the Connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pSsomAzQfSnJAcBPIFBq5g.png" /></figure><p>Once the table is created, add a sample value to the table. For this article, I am adding a stock_id as “MU” with a stock_value as “65”. Since DynamoDB is a NoSQL DB, in addition to the primary key, we can add any number of values to the existing table.</p><p>Please note that the Primary Key is mandatory to add.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AV9IkWjwG6iIvsqHLYBCXQ.png" /></figure><p>If you see your Table similar to the image below, then Congratulations..!!! You have created and added a sample value to your first DynamoDB Table. Way to go..!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lNB2I96OFZG0dstfXfZ34A.png" /></figure><blockquote>3. Setup the Java Spring Boot Micro Service on your local using Spring Initializr.</blockquote><p>Let us know setup the Java Project where you create the Micro Service and connect this MicroService to the DynamoDB table which you just created.</p><p>Go to the Spring Initializr URL, where you can create the basic Spring Boot Project located at:</p><p><a href="https://start.spring.io/">Spring Initializr</a></p><p>Just give the appropriate GroupId and the Artifact Id and add some basic dependencies to kick start your Apring Boot Application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6_8IfBelAVs5s772lTKGg.png" /></figure><p>Once you have the Project downloaded, just modify your application.properties file to run this project on a local port and the context path</p><blockquote>server.servlet.context-path=/dynamodb-learnings</blockquote><blockquote>server.port = 6060</blockquote><p>Your Application now runs on Port 6060. I used port 6060 to keep it unique and avoid port clashes. You are free to use any port you please.</p><blockquote>4. Integrate the DynamoDB code into your Java Application using AWS SDK and successfully read the sample value.</blockquote><p>This is the meaty part of the Application where you write the code to connect to the DynamoDB Table on your AWS.</p><ol><li>Add the appropriate required dependencies to your pom.xml file.</li><li>Create a Configuration Class and create the DynamoDB Java Bean with the appropriate Configurations.</li><li>Create a Model package to create the Class which maps to the DynamoDB Table.</li><li>Create a Repository Class to read the value from DynamoDB Class.</li><li>Create a Controller to expose a GET HTTP Endpoint.</li></ol><blockquote>Add the appropriate required dependencies to your pom.xml file</blockquote><p>Add the “aws-java-sdk-core and “aws-java-sdk-dynamodb” dependencies to you pom.xml and do an “mvn clean install” on your project to download the appropriate dependencies.</p><p>Once the dependencies are downloaded,</p><blockquote>Create a Configuration Class and create the DynamoDB Java Bean with the appropriate Configurations.</blockquote><p>Create a package called config and create a class called “DynamodbConfiguration class as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*3NsOOsW3XtnKtSxrUfuMYg.png" /></figure><p>In the above code, we are creating a bean called “dynamoDBMapper” which connects to the table called “stocks” in the ‘us-east-1&quot; region on a Standard Client Builder. This is how the DynamoDB Client is created and it reads the standard [default] values in your ./aws/credentials file and connects to the appropriate account. It further looks up for the table mentioned and then hooks itself up to the corresponding table in the account.</p><p>The above step is used to connect to DynamoDB on local. If you have Profiles mentioned in your ./aws/credentials, then you might want to use `AWSStaticCredentialsProvider` and this connects to the spcific Profile.</p><p>I will be covering how to deploy this into an EC2 Instance and to connect via an IAM role in a separate article.</p><blockquote>3. Create a Model package to create the Class which maps to the DynamoDB Table.</blockquote><p>Create a POJO to Serialize and Unserialize the data to and from the DynamoDB table into your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*AXdysuhkWa4YVZXX_p0s_Q.png" /></figure><p>Add the appropriate getters and setters or use the “lombok” dependency and use the Annotation “@Data” on the top of the class to eliminate lines 10 to 24 from your code. Im explicitly going with Getters and Setters here.</p><p>Mention the HashKey and the Attribute values as applicable.</p><blockquote>4. Create a Repository Class to read the value from DynamoDB Class.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*YE-4iLxVjXrqx6DkQXBiGg.png" /></figure><p>Line 24: Import the Bean created in Step 2 into the Repository Class. The Bean is very important as it’s created only once during the Service Start up and resolves itself into the table connection and is re-used for further multiple connections.</p><p>Line 34: Expression Attributes are being built. The key to lookup here is: “stock_id”</p><p>Line 36: Expression Attribute values are being built. The value to lookup here is “MU” — which is what we have given during the table creation.</p><p>Line 40: DynamoDBQueryExpression is being built and all the parameters built above are being utilized to build the Query.</p><p>Line 41: Breaking down the condition for lookup on the table which is equivalent to `stock_id == MU’` based on the parameters supplied on Line 42 and 43.</p><p>Line 47: This is where the magic happens. We are querying the page with our conditions of lookup and the DeSerializer class — “Messages” which parses the JSON into POJO.</p><blockquote>5. Create a Controller to expose a GET HTTP Endpoint.</blockquote><p>We are now getting the data from DyamoDB and we need to return this data to the caller.</p><p>Let’s build a Controller class and expose a HTTP Endpoint for us to call and get the data via Curl or Postman.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*hvQUTvXjhXwckEK5tJzGsQ.png" /></figure><p>Build a “Rest Controller” with a sample GET endpoint. Autowire the Repository Class and call the getDetails method and return the data to the caller.</p><p>Im keeping this GET Endpoint very simple as I have hard coded the value to lookup. Feel free to pass a Path Parameter or convert this to POST as you please. Theprimary focus of this article to talk about D configuration and a sample lookup usinf AWS SDK in Java.</p><p>Run the Server. Your Application shoud run on Port 6060 on localhost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SPY-thC7SzBlar_S3vbLCw.png" /></figure><p>Making a sample Postman call should return the appropriate value which we have added in the AWS Console.</p><p>If you see this response, then Vioala…!!! You have successfully connected your MicroService to a real DynamoDB table and are able to retrieve the values.</p><p>You can find this project on github in the link below. Feel free to clone and enhance it as you please.</p><p><a href="https://github.com/teja24nex/dynamodb-learnings">teja24nex/dynamodb-learnings</a></p><p>Bravo…!! This is a brilliant first step towards DynamoDB. Now you can explore more options to read more dynamic Values and add queries to add new values and sky is the limit for the operations. Feel free to explore more.</p><p>I hope this article of mine has shed some light on how to connect to DynamoDB from your Java Micro Service Application and read the values. Happy Coding…!!</p><p>If you have liked what you read, Please Clap hands below as many times as you can as this encourages me to write more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e86a430d418e" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/connect-your-micro-service-spring-boot-application-to-aws-dynamodb-e86a430d418e">Connect your Micro Service (Spring Boot Application) to AWS DynamoDB</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chaos Engineering — How to break AWS Infrastructure on purpose]]></title>
            <link>https://levelup.gitconnected.com/chaos-engineering-how-to-break-aws-infrastructure-on-purpose-3a48ba32aa2e?source=rss-248b5a922263------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a48ba32aa2e</guid>
            <category><![CDATA[chaos-testing]]></category>
            <category><![CDATA[chaos-monkey]]></category>
            <category><![CDATA[disruption]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[chaos-engineering]]></category>
            <dc:creator><![CDATA[Teja Swaroop Mylavarapu]]></dc:creator>
            <pubDate>Wed, 24 Jun 2020 12:41:02 GMT</pubDate>
            <atom:updated>2026-01-11T17:27:29.238Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chaos Engineering — How to break your AWS Infrastructure on purpose</h3><p>Breaking your System Infrastructure on purpose — Really? Why would anybody do that?</p><p>Breaking your Infrastructure on purpose and setting up the baseline for disasters is the first step for Resilient Architecture of Production Systems. It can be achieved with various Experiments and be tested robustly for a better Resiliency Posture.</p><p>We are going to discuss:</p><ol><li>What is Chaos Engineering and the importance of it.</li><li>Addressing Prerequisites — Setup your AWS Account, CLI on your Terminal, Setup Infra (Create Auto Scaling Group (ASG) and attach 3 EC2 Instances)</li><li>Setting up our first Chaos Experiment — Determine the steady state hypothesis and Delete an random EC2 Instance using AWS CLI</li><li>Chaos Experiment Observation — Check your Infra Robustness and complete your Chaos Experiment.</li><li>Other types of Chaos Experiment ideas which can be implemented (Some Interesting thoughts..!!!).</li></ol><blockquote>1. What is Chaos Engineering and the importance of it.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*lbMxBjhAaH_1ckgthGekQQ.png" /></figure><p>Chaos Engineering is a type of Engineering where we test the system’s robustness, reliability and the ability to survive a disaster without manual intervention.</p><p>It is a process where we manually disrupt our Infrastructure productively and test how quickly and efficiently our Applications and Infra Autoheal themselves and their ability to thrive during a disaster or any System Catastrophe.</p><p>Sounds interesting, huh?</p><p>Well, it is very interesting because we would be experimenting, playing and disrupting our Infra and keenly observe how it reacts, learn and improve from it. This makes our Infra robust, stable and exhibit more confidence on our production stacks (which, I think is very important).</p><p>We will be knowing the weakness and the leaks in our system and help us overcome the issues beforehand in our Test Environment.</p><p>There are many Chaos experiments we can perform on our system like deleting a random EC2 Instance, deleting Services and etc which we shall explore in the last section.</p><blockquote>Addressing Prerequisites — Setup your AWS Account and CLI on your Terminal</blockquote><p>Let’s get our hands dirty by setting up our Infra ready to disrupt.</p><blockquote>Prerequisites:</blockquote><ol><li>Get the Access Key ID and Secret Access Key from AWS Account</li><li>Install AWS CLI on your local machine</li><li>Configure AWS credentials for the AWS Account on your machine</li><li>Setup Infra — Create an Auto Scaling Group and attach 3 EC2 Instances to it as desired and Min Capacity (Assume Tasks/Services are running inside it).</li><li>Validate AWS CLI by checking the number of Instances against the newly created ASG.</li></ol><blockquote>Get the Access Key ID and Secret Access Key from AWS Account</blockquote><p>Go to <a href="https://aws.amazon.com/console/">https://aws.amazon.com/console</a>/ and login to the AWS Console. Navigate to IAM section-&gt;Dashboard-&gt;Manage Security Credentials → AccessKeys Tab and extract your Access Key ID and Secret Access Key.</p><p>Go ahead and Create on if you don’t have one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sgiktbAy8vkC-3cCI7Oryw.png" /><figcaption>AWS Access Keys (Masked for Security)</figcaption></figure><blockquote>Install AWS CLI on your local machine</blockquote><p>After jotting down the keys, let’s install AWS CLI v2 on your system. If you already have this configured, please proceed to Step 3 where we create the AWS Infra.</p><p>Install AWS CLI by following the commands mentioned in the AWS documentation.</p><p><a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html">Installing, updating, and uninstalling the AWS CLI version 2 on macOS</a></p><p>After installing AWS CLI, go to your mac Terminal and type in aws and that should list something like the image below. This confirms and validates that AWS CLI has been successfully configured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*JsrxGjSDiySRVvDLIysBJA.png" /><figcaption>AWS CLI Validation</figcaption></figure><blockquote>Configure AWS credentials for the AWS Account on your machine</blockquote><p>Now, time to map your AWS Credentials on your local machine. We need to configure the Access Key ID and Secret Access Key on your machine so that you can connect to yourAWS Account from your machine and create and disrupt the Infra using AWS CLI.</p><p>aws configure should do the trick and ask for the Credentials, region and the output format. You might want to configure it as the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*K1QLE3YxWS8muyvxdiN3Ng.png" /></figure><p>We can validate this by going to your ~/.aws/credentials</p><p>This file validates the Credentials we have just added in the terminal and displays the keys. With this step finished, we now have access to the AWS Account from our machine through AWS CLI. Eureka…!!!</p><blockquote>Setup Infra — Create an Auto Scaling Group and attach 3 EC2 Instances to it as desired and Min Capacity (Assume Tasks/Services are running inside it).</blockquote><p>We will be using the AWS CLI to create a Chaos Experiment and disrupt the Instances. For the time being we shall create an Auto Scaling Group and attach 3 EC2 Instances using the AWS Console.</p><p>Go straight to AWS Console and search for EC2 and go to the tab of “Auto Scaling Groups” and Create a new Auto Scaling Group.</p><p>a. Select the Appropriate Instance type (preferably a t2.micro -free tier)</p><p>b. Create a new Launch Configuration and associate an IAM role if you have one.</p><p>c. Create the ASG with a minimum of 3 EC2 Instances and a max of 6 Instances and add it in the required VPC and Subnets. Defaults are sufficient for this sample Experiment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*beHBcRdlW9RAbt3L730BSQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*U1kFKSInoCH1WLwFVcjXvg.png" /></figure><blockquote>Validate AWS CLI by checking the number of Instances against the newly created ASG.</blockquote><p>New ASG gets created and 3 new EC2 Instances gets automatically launched and come to a steady state. We have established the Infra. For this Experiment, we can assume that this is how our backend Infrastructure is setup and now we shall start disrupting. We can discuss more disruption techniques in the last section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qhaUq3RMLcH0XjZtZ1IBhg.png" /></figure><blockquote>Setting up our first Chaos Experiment — Determine the steady state hypothesis and Delete an random EC2 Instance using AWS CLI</blockquote><blockquote>Chaos Experiment Setup:</blockquote><p>Now, we shall disrupt a random EC2 Instance from our Auto Scaling Group intentionally and observe how it Autoheals itself and restabilizes itself. We shall test the availability of our Instances and carefully perceive the time it takes to come to a stady state.</p><p>Go to your terminal and get the list of EC2 Instances that are associated with our ASG. We shall get the list and the Instance details and its IDs.</p><p>We shall pick a Random Instance from this List, get the Instance ID out of it and supply CLI commands to terminate this random Instance dynamically and observe how the Autoheal happens.</p><blockquote>Get the ASG details: Our ASG Name which I created is “medium-asg”</blockquote><p>aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name medium-asg</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*StO0OtrLyAnnNf9_HR6HRg.png" /></figure><p>The above list inside the ‘Instances’ section confirms that we currently have 3 EC2 Instances running in our AWS account within our ASG.</p><blockquote>Now, lets extract an EC2 Instance ID</blockquote><p>InstanceID=`aws autoscaling describe-auto-scaling-groups — auto-scaling-group-name medium-asg — query AutoScalingGroups[0].{val:Instances[0].InstanceId} — output text`</p><p>We are traversing through the JSON which we received above and looping inside to extract the instanceId from the first value of the array and assign it to the temporary variable InstanceID. We shall pass this variable to our next command where it terminates the Instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RYKwHJXnBArrJwfVy_dtzg.png" /></figure><blockquote>Delete the Instance from the ASG</blockquote><p>aws autoscaling terminate-instance-in-auto-scaling-group — instance-id $InstanceID — no-should-decrement-desired-capacity</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N-OFU37TGUyiaSx1QJSZEQ.png" /></figure><p>The response shoud return a JSON which says that the Instance is being taken out and is in Progress.</p><blockquote>Chaos Experiment Observation — Check your Infra Robustness and complete your Chaos Experiment.</blockquote><p>Go to the AWS Console immediately and open the EC2 Instances section. We must observe that our EC2 Instance (The ID which we served in the above terminating command) is Terminated or must be in the process of getting terminated.</p><p>New EC2 Instance should also be coming up immediately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U_opBoMmExuWEXiZ-krUlQ.png" /></figure><p>This si the main important step in this experiment as this establishes that our Infra is stable and a new Instance is coming up in the same Availability Zone. Please note that this new Instance might or might not come up in the same AZ. It depends on how many AZs have been defined while creating the ASG ensuring us the maximum Availability.</p><p>If the old EC2 Instance is not terminated or if a new EC2 Instance does not come up, then we might want to check the ASG Poliy Configurations.</p><p>If you have come this far, then Congratulations…!!! You HAVE finished your first Chaos Experiment. Great Job on that.</p><blockquote>Other types of Chaos Experiment ideas which can be implemented (Some Interesting thoughts..!!!).</blockquote><p>This is a very small experiment we have conducted here disrupting a random EC2 Instance. We can extend this disruption to many of them and schedule various Experiments on your Infrastructure to boost your Confidence Level.</p><ol><li>Stop a random ECS Service running on your Cluster and see how your ECS brings up a new Service — The time it takes ECS to bring up the new Service should be relatively very quick compared to EC2 Instance.</li><li>Bring does the number of ECS Services down to a desired level. For Example, configure your commands/experiment to bring down the ECS Services(Tasks) to 50%. — As soon as you bring these tasks down, ECS should kick in and bring those up. Observe this on the AWS Console at the Cluster level.</li><li>Bring down the number of Instances in your ASG down to 50% or 75%. Keep hitting your ELB during this disruption and observe the number of 5xx erros you get. You might want this number to be very low.</li><li>If your Application is resilient on different regions like us-east-1 and us-west-1 and you have Auto Failover enabled at the Route 53 level, then go ahead and disrupt a region. Schedule your Experiment to bring down the entire region by deleting all the instances in one region and see how quickly and efficiently your Infrastructure Failovers to the Other region. — This should be fast and quick or else you will end up with more errors. Route 53 is smart to determine, but still we need to have the metrics with Chaos.</li><li>If your have a microservice running as a Producer or as a Consumer on Apache Kafka, then disrupt your topic on one region and make sure your failover topics are disabled and the failover is seamless.</li><li>In your micro service, introduce a function which kicks in after a period of time and throws 5xx randomly. Make sure your CloudWatch Alarms kick in and failover or act accordingly as expected.</li></ol><blockquote><strong><em>Please note: It is always advisable to have a JMeter Script running against your Microservice/API while the experiment happens so that we can track the Metrics on how our Applications responds during Chaos.</em></strong></blockquote><p>Our target is to have minimal number of Errors. If the number of errors are more, we need to fine tune our Infra, our alarms and our failover techniques for better results.</p><h3>Summary:</h3><p>We framed <strong>chaos engineering on AWS</strong> as a controlled, hypothesis-driven practice for validating resiliency: define a steady state, inject a bounded failure, observe with telemetry, and convert findings into concrete hardening (alerts, runbooks, scaling/failover tuning). The core innovation is its <strong>“minimal tooling” on-ramp</strong> — positioning AWS-native primitives (e.g., compute groups, automation via CLI/ops workflows) as sufficient to start running meaningful failure experiments, rather than requiring a dedicated chaos platform from day one. A second contribution is the <strong>operational emphasis</strong>: the experiment is treated as a repeatable procedure with an explicit blast radius and verification steps, which aligns with AWS guidance on safe experimentation and rollback/guardrails. Finally, the article’s value is in encouraging readers to expand beyond a single fault into a portfolio of experiments (compute loss, dependency degradation, routing/failover), turning resilience into a measurable engineering loop rather than an assumption.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a48ba32aa2e" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/chaos-engineering-how-to-break-aws-infrastructure-on-purpose-3a48ba32aa2e">Chaos Engineering — How to break AWS Infrastructure on purpose</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</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 Horizontally and Vertically Autoscale your Application with AWS EC2 Instances and Docker]]></title>
            <link>https://medium.com/swlh/how-to-autoscale-your-application-with-aws-ec2-instances-and-docker-containers-975ab1263454?source=rss-248b5a922263------2</link>
            <guid isPermaLink="false">https://medium.com/p/975ab1263454</guid>
            <category><![CDATA[horizontal-scaling]]></category>
            <category><![CDATA[autoscaling]]></category>
            <category><![CDATA[ec2-instance]]></category>
            <category><![CDATA[vertical-scaling]]></category>
            <category><![CDATA[docker-container]]></category>
            <dc:creator><![CDATA[Teja Swaroop Mylavarapu]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 21:10:26 GMT</pubDate>
            <atom:updated>2026-01-11T17:06:05.884Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Horizontally and Vertically Autoscale your Microservice with AWS EC2 Instances and Docker Containers</h3><p>AutoScaling — In this world of Cloud era, one might have heard this word frequently and this is one of the key components of our Architecture where we want our Infrastructure to Autoscale Up and Down based on the traffic.</p><p>I am going to talk about …</p><ol><li>Explain the definitions of Vertical and Horizontal AutoScaling.</li><li>The memory and CPU allocations for EC2 instances.</li><li>Right size the docker container and determine the criteria for Autoscaling.</li><li>Autoscale up and down virtually and Calculate the Formula.</li></ol><blockquote>1. Explain the definitions of Vertical and Horizontal AutoScaling.</blockquote><blockquote>Explaining the Infrastructure Setup:</blockquote><p>At the Infra Level, we usually deploy our Applications in EC2 Instances. For scalability, we deploy on multiple EC2 Instances for load balancing and High Availability.</p><p>Depending on the configuration we provide, 1 EC2 Instance can have multiple docker containers (ECS Services/Application) running inside it on different ports.</p><p>First things first, Let me clarify the definitions of Vertical and Horizontal Scaling of an Infrastructure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*shIXDLiIvV9Gg9DuutWsIg.jpeg" /><figcaption>Horizontal and Vertical Scaling</figcaption></figure><blockquote>What is Vertical Scaling?</blockquote><p>Vertical Scaling is the act of adding more docker containers (ECS Services) to your existing Infrastructure.</p><p>Let’s say, you have 1 EC2 Instance and have 1 Docker container deployed on it. Once the Application goes live, the traffic and the number of requests has surpassed our expectations thereby causing failures and existing one Docker container not able to handle the load. We can resolve the situation by Vertical Scaling and add one more docker container (adding CPU and memory) with the same configuration. This way the load gets balanced across the 2 Docker containers bringing the situation under control.</p><blockquote>What is Horizontal Scaling?</blockquote><p>Horizontal Scaling simply put is the act of adding more horsepower in the form of adding more EC2 Instances to the existing Infrastructure.</p><p>Taking the above example forward, let’s say the incoming traffic is growing leaps and bounds bombarding our Application and adding that extra docker container is still not sufficient to meet the demand.</p><p>What do you do? — Simple, add one more docker container. Well, the answer is partially right, but what if the existing EC2 Instance do not have the Memory or CPU to hold the new docker container.</p><p>In this case, we Horizontally scale up the Infra by adding one more EC2 Instance to the battalion and then vertically scale the Infra by adding one more docker container and then the incoming requests gets load balanced among the 3 docker containers.</p><p>This process gets scaled up and repeated automatically till the Incoming load is efficiently handled by our Application.</p><p>We will get how the Autoscaling happens the various criteria to Autoscale in the coming sections.</p><blockquote>2. The memory and CPU allocations for EC2 instances.</blockquote><p>EC2 Instances obviously comes with Memory and CPU allocated to it. Different type of EC2 instances have different type of Memory and CPU allocated to it.</p><p>For Example let’s take the example of the t2 family where the Memory and CPU are as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*ac_ls5ioEv0-vJ8gzRk8OQ.png" /></figure><p>I have converted the above chart to Binary in MB for better understanding purposes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BvQhYFhrLuARqix018Y-og.png" /></figure><p>These are the allocation sizes that are available for our EC2 Instances. The docker containers while getting deployed mount their memory and CPU from the Host (EC2 Instances). So a docker container needs to be allocated a percentage of Memory and CPU of the EC2 instance.</p><blockquote>3. Right size the docker container and determine the criteria for Autoscaling.</blockquote><blockquote>Right Size the docker container —</blockquote><p>For better understanding, let us take the example of t2.medium and right size our docker container reservations.</p><p><strong><em>Total Amount available: </em>CPU: 2048 MB and Memory: 4096 MB</strong></p><p>Our docker container should always be a small subset of the host.</p><p>A 20% is usually allocated as buffer and for any additional OS which leaves us with 80%.</p><p><strong>Amount left — CPU: 1638 MB and Memory: 3276 MB</strong></p><p>Let’s talk about EC2 Instance Scaling policy conditions before we decide on the docker size.</p><p><strong><em>Condition 1</em></strong>: EC2 Instance scale up (Horizontal Scaling) should happen if the CPU Reservation is above 80%, meaning if the CPU Reservation within an EC2 instance rises above 80%, it autoscales and adds one more EC2 Instance thereby bringing down the entire CPU Reservation.</p><p><strong><em>Condition 2</em></strong>: EC2 Instance scale in (Horizontal Scaling) should happen at 38%. If the CPU reservation is less than 38%, then the extra Instance should be scaled down.</p><p><strong>Condition 3</strong>: Docker scale up (Vertical Scaling) will happen if the overall CPU Utilization has hit 60% (this includes the sum of all the docker containers Utilization).</p><p><strong>Condition 4</strong>: Docker scale in(Vertical Scaling) will happen if the overall CPU Utilization has goes below 20%(this includes the sum of all the docker containers Utilization).</p><p>Conditions can be applied on Memory as well.</p><p>Based on the above criteria, let’s allocate the docker memory and CPU to 20% of the host (EC2 Instance).</p><p>So, each docker container would take:</p><blockquote>CPU for docker — 20% of 2048 = ~409 Mb</blockquote><blockquote>Memory for docker — 20% of 4096 = ~819 Mb</blockquote><p>Overall, each docker container would be reserved a — CPU of 409Mb and Memory of 819Mb.</p><p>We will discuss on the concept of number of docker containers and EC2 Instances in the next section.</p><blockquote>4. Autoscale up and down virtually and Calculate the Formula.</blockquote><p>Now, Let’s play a game. Let’s decide virtually on the number of EC2 Instances and the docker containers and start writing the formula. Stay the course with me, I shall elucidate as much as I can.</p><p>Lets us initially go with 1 EC2 Instance and 2 docker containers.</p><blockquote><strong><em>Please note in the below calculations, the Numerator is for the Docker and the denominator is for the EC2 Instance.</em></strong></blockquote><p>a. 1 EC2 Instance</p><p>b. 2 docker containers deployed with 20% CPU and Memory Reservation leading to 40% of Reservation from EC2 Instance</p><blockquote>Reservation is now at 40 (20 *2) /100 , Horizontal scale up should happen above 80% (Condition 1).</blockquote><p>c. Now, let’s assume your API is serving more traffic with CPU Utilization going above 60% (Condition 3) and Vertical (Docker) Scaling happened and 3rd docker container came up.</p><blockquote>Reservation = 60 (20*3) / 100, Horizontal scale up should happen above 80% (Condition 1).</blockquote><p>d. Again Horizontal Scaling happened and 4th docker container came up.</p><blockquote>Reservation = 80 (20 *4) / 100.</blockquote><blockquote>Horizontal Autoscaling will happen now as the Reservation has hit our threshold of 80%. A 2nd EC2 Instance has now come up changing the calculation to</blockquote><p>Reservation = 80 / 200 (100 +100) = 40%</p><p>Scaling down should happen at 38% (Condition 2) based on Step 3 in the previous section which means the new Instance would stay.</p><p>e. Again, Vertical Scaling happened and 5th docker container came up.</p><blockquote>Reservation = 100 (20 *5) / 200 (100+100) = 50%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>f. Vertical Scaling happened and 6th docker container came up.</p><blockquote>Reservation = 120 (20*6) / 200 (100+100) = 60%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>g. Vertical Scaling happened and 7th docker container came up.</p><blockquote>Reservation = 140 (20*7) / 200 (100+100) = 70%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>h. Vertical Scaling happened and 8th docker container came up.</p><blockquote>Reservation = 160 (20*8) / 200 (100+100) = 80%.</blockquote><p>Now again Autoscaling will happen as it has hit our threshold of 80%.</p><blockquote>Reservation = 160 (20*8) / 300 (100 *3) = 53.3%.</blockquote><blockquote>Horizontal Scale up happens at 80%, Scale down happens at 38%. We are good.</blockquote><p>So now, overall we have 8 docker containers and 3 EC2 Instances scaling up seamlessly. Now, let’s assess the scale down scenarios on a step by step basis.</p><p>a. Due to low traffic, Scale down happened and the Docker containers scaled down to 7.</p><blockquote>Reservation = 140 (20*7) / 300 (100*3) = 46.6%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>b. Scale down happens and the Docker containers scaled down to 6.</p><blockquote>Reservation = 120 (20*6) / 300 (100*3) = 40%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>c. Scale down happens and the Docker containers scaled down to 5.</p><blockquote>Reservation = 100 (20*5) / 300 (100*3) = 30%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>Since it has hit the threshold of 38% for scaling down, the EC2 Instance scale down happens and the count shoots down to 2.</p><blockquote>Reservation = 100(20*5) / 200 = 50%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>d. Scale down happens and the Docker containers scaled down to 4.</p><blockquote>Reservation = 80(20*4) / 200 (100*2) = 40%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>e. Scale down happens and the Docker containers scaled down to 3.</p><blockquote>Reservation = 60(20*3) / 200 (100*2) = 30%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>Since it has hit the threshold of 38% for scaling down, the EC2 Instance scale down happens and the count shoots down to 1.</p><blockquote>Reservation = 60(20*3) / 100 = 50%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>f. Scale down happens and the Docker containers scaled down to 2.</p><blockquote>Reservation = 40(20*2) / 100 = 40%. Horizontal Scale up happens at 80%, Scale down happens at 38%</blockquote><p>So, finally we came back to where we were initially with 1 EC2 Instance and 2 docker containers.</p><p>I shall leave it to your discretion depending on your Application on how many Instances and docker containers you need to start with, but the basic Formula stays the same and based on the numbers above, it can safely be applied on your Infrastructure.</p><h3>Summary:</h3><p>In conclusion, this work presented a practical autoscaling framework for containerized applications deployed on AWS EC2, emphasizing the need to jointly manage elasticity at two distinct layers:</p><p>1. S<strong>ervice/task scaling</strong> (i.e., adjusting the number of Docker containers to meet workload demand) and</p><p>2. I<strong>nfrastructure scaling</strong> (i.e., adjusting the number of EC2 instances to maintain sufficient compute and memory capacity for container placement).</p><p>The central contribution is a capacity-aware approach that treats host resources as explicit constraints and uses container CPU/memory reservations to translate abstract “load” into measurable scheduling pressure.</p><p>Using representative EC2 instance characteristics, the article demonstrated how to derive a conservative operating envelope by reserving headroom for the operating system, background processes, and transient workload bursts, rather than targeting full utilization. This enables policy design that is both stable and reproducible: container-level scaling can be triggered by utilization signals to maintain service responsiveness, while instance-level scaling is driven by higher-threshold indicators of cluster saturation (e.g., aggregate reservation or sustained host pressure) to prevent placement failures and performance collapse. Conversely, scale-in behavior is structured to reduce service capacity first and retire infrastructure only when resource reservations fall below a lower bound, thereby mitigating oscillation and reducing the likelihood of thrashing.</p><p>The takeaway: autoscaling works best when you treat it as a <strong>controlled feedback loop</strong> — measure, reserve capacity intentionally, keep buffer, and let containers and instances scale in the right order. This approach keeps performance consistent, improves resilience under spikes, and prevents unnecessary infrastructure cost during low traffic periods. The resulting methodology offers practitioners a repeatable blueprint for configuring EC2- and container-level autoscaling policies that balance performance, resilience, and efficiency — particularly in environments where multiple containers are colocated per instance and resource fragmentation can otherwise lead to unpredictable scaling outcomes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=975ab1263454" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-autoscale-your-application-with-aws-ec2-instances-and-docker-containers-975ab1263454">How to Horizontally and Vertically Autoscale your Application with AWS EC2 Instances and Docker</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Self Signed Certificate (Keystore) using keytool and host your Spring Boot Application on…]]></title>
            <link>https://medium.com/swlh/create-a-self-signed-certificate-keystore-using-keytool-and-host-your-spring-boot-application-on-d29fe3a15043?source=rss-248b5a922263------2</link>
            <guid isPermaLink="false">https://medium.com/p/d29fe3a15043</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[self-signed-certificate]]></category>
            <category><![CDATA[keytool]]></category>
            <category><![CDATA[keystore]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Teja Swaroop Mylavarapu]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 14:23:44 GMT</pubDate>
            <atom:updated>2026-01-11T14:29:32.487Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to create a Self Signed Certificate (Keystore) using keytool and host your Spring Boot Application on ‘HTTPS’ protocol</h3><p>HTTPS — We all know that https stands for Hyper Text Transfer Protocol Secure.It is the de-facto standard protocol to load and serve all the Applications out there.</p><p>It is used as a secure way of communication over the network between systems. HTTPS adds an extra layer of security using TLS. I will not digging over the 7 layer TCP/IP models in this article, but rather focus on how to build your Application on HTTPS.</p><blockquote>What will I be talking in this article:</blockquote><p>Step 1: Create a simple Spring Boot Application using Spring Initializr</p><p>Step 2: Build a sample ‘GET’ endpoint on your Application’s Controller level</p><p>Step 3: Host this Application on ‘HTTP’ on localhost</p><p>Step 4: Create a Self Signed Certificate (keystore) in PKCS12 format using ‘keytool’</p><p>Step 5: Apply this certificate to your Spring Boot Application and host the Application (API) on ‘HTTPS’.</p><blockquote>Please note, this article only focuses on hosting your Application securely on your local (localhost) to kickstart development and play around code. While working at an Enterprise Level, all the companies have their own Certs for TLS and they should be honored unquestionably.</blockquote><p>With the above steps, we can straight away start developing our Application on HTTPS Protocol right from our dev environment and need not wait till we deploy our Application on AWS or Azure to validate TLS. This ensures our first step of proper validation and also helps transmit data securely.</p><blockquote>Step 1: Create a simple Spring Boot Application using Spring Initializr</blockquote><p>a. Go to <a href="https://start.spring.io/">https://start.spring.io/</a> and start creating a new Spring Boot Project.</p><p>b. Type in the appropriate Group and Artifact Id and Java Version. Below is what I am going with during the time of the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DDwGQDTKfNg40XFyXfjksA.png" /></figure><p>Download the Project and extract the Zip file and open it up in your favorite editor. I will be using Spring Tool Suite — STS.</p><blockquote>c. Do an mvn clean install on your project source to download all the dependencies.</blockquote><p>d. Go to ‘src/main/resources/application.properties’ and let’s add some context path and port numbers.</p><blockquote>server.servlet.context-path=/validate-learnings</blockquote><blockquote>server.port=8082</blockquote><blockquote>Step 2: Build a sample ‘GET’ endpoint on your Application’s Controller level</blockquote><p>Create a new Controller package and create a Resource class to create a new endpoint for health check.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HEqK_RNTKM5ARkmbvrBH8A.png" /></figure><blockquote>Step 3: Host this Application on ‘HTTP’ on localhost</blockquote><p>Run the Spring Boot Application and ensure the App runs on port 8082.</p><p>Open Postman and hit the localhost on port 8082 on the “/validate-learnings/health” endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cIZqxVYqvDCyvuCuuVE8WQ.png" /></figure><p>Returning ‘success’ ensures that the Application has been successfully hosted and running successfully.</p><p>Now, with the basics set up and the Application running on HTTP, let’s create a self signed certificate and that keystore to your Application and run this App on ‘HTTPS’.</p><blockquote>Step 4: Create a Self Signed Certificate (keystore) in PKCS12 format using ‘keytool’</blockquote><p>Let’s generate the Certificate using keytool. Java Keytool is a command line tool used to generate Public/Private Keys and store them in Java’s Keystore. Keytool command is available from your JDK’s bin folder or globally if you have setup with Environment Variable to it.</p><p>Type in the below command to generate the Cert. We shall go step by step on what it does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TQVtx0kZM7brxMWamkrbvw.png" /></figure><ul><li>alg: Encryption Algorithm as RSA</li><li>keysize: 2048 (Very secure — Higher the number, better the security)</li><li>storetype: pKCS12</li><li>Keystore: keystore.p12 — name of the Cert</li><li>validity: 3650 — Valid for 10 years.</li></ul><p>The above command generates a new Certificate after asking a few questions about passwords and a bunch of other details. Once this is created, it is ready to use.</p><blockquote>Step 5: Apply this certificate to your Spring Boot Application and host the Application (API) on ‘HTTPS’.</blockquote><p>Copy this Certificate into ‘src/test/resources’ and update your application.properties as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vq9HtqY0vPLVqigEXikv8Q.png" /></figure><p>After updating the application.properties, we are good to run the application on localhost on port 8082 again, but this time with ‘HTTPS’.</p><p>Do not keep the password as plain text while hosting on Servers, please use the appropriate Security mechanisms like Vault to store your passwords. The above image is for demo purposes only.</p><p>Open Postman and hit the Application with ‘HTTPS’ protocol and it should yield the same result as before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gxJOdtw8nII5qYlPehoY1g.png" /></figure><p>Voila…!!! There you are… You have just created a Self Signed Certificate and hosted your Application on HTTPS making it more secure honoring TLS.</p><p>It is a good practice to host Applications on HTTPS and keep it more secure even on your local and now you can more confidently host your Application on any Servers going forward.</p><p>I hope this article of mine has thrown some light in how to host your Applications on HTTPS with your own Certificates. Happy Coding…!!!</p><p>If you like this article, please do Clap hands at the bottom of the page as many times as you can. It encourages me to write more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d29fe3a15043" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/create-a-self-signed-certificate-keystore-using-keytool-and-host-your-spring-boot-application-on-d29fe3a15043">Create a Self Signed Certificate (Keystore) using keytool and host your Spring Boot Application on…</a> was originally published in <a href="https://medium.com/swlh">The Startup</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 efficiently host your Web Applications (UI)on S3 Buckets through AWS CloudFront]]></title>
            <link>https://medium.com/swlh/how-to-efficiently-host-your-web-applications-ui-on-s3-buckets-through-aws-cloudfront-156838f4b287?source=rss-248b5a922263------2</link>
            <guid isPermaLink="false">https://medium.com/p/156838f4b287</guid>
            <category><![CDATA[aws-s3-bucket]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloudfront]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[bucket-policy]]></category>
            <dc:creator><![CDATA[Teja Swaroop Mylavarapu]]></dc:creator>
            <pubDate>Sat, 23 May 2020 19:44:43 GMT</pubDate>
            <atom:updated>2020-06-24T12:44:03.538Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to efficiently host/deploy Web Applications(UI)on S3 Buckets through AWS CloudFront</h3><p>Are you considering of hosting your dynamic UI Web Application on AWS in the most inexpensive and efficient manner?</p><p>And, did you say EC2 Instances?</p><p>If the answer to the above questions are YES, then read on …..</p><p>Well, let’s face it. EC2 instances are expensive and usually dent a hole in your wallet.</p><p>I am not against EC2 instances. I love the way the Servers spin up rapidly with the desired configuration and load up in minutes. With the support of ELBs and ASGs, I also like the way they Autoscale and balance out the traffic.</p><p>The above approach best suits for heavy Server dependent scenarios like hosting an API, but I believe hosting a UI Application is definitely not one of them. For the cost and effort that is involved with EC2 Instances and ELB (Elastic Load Balancer), it’s definitely an overkill.</p><blockquote><strong><em>What is the Alternative that am I going to talk about in this article?</em></strong></blockquote><p>In this article, I am going to build a small UI Web Application using Angular. This Web Application will be hosted on an S3 bucket (Private, not Public) and will be served on to the internet via CloudFront (AWS CDN)and can be extended further to Route53 (You can even map this to your Web Domain name, if you have one).</p><p>My major focus will be on the Operations (Ops) side where I try to show the deployment and hosting part and a very minimal effort will be spent on the UI Application Development (Dev).</p><blockquote><strong>Steps to be covered:</strong></blockquote><p>Step 1: Build a small Angular Application using Angular CLI.</p><p>Step 2: Create an S3 bucket on AWS and host this code on the S3 Bucket.</p><p>Step 3: Create a CloudFront URL and map it to the newly created S3 bucket.</p><p>Step 4: Verify the S3 bucket policy.</p><p>Step 5: Test the CloudFront URL.</p><blockquote>Step1: Build an Angular Application using Angular CLI.</blockquote><p>a. Download and install NodeJS using the link —</p><p><a href="https://nodejs.org/en/download/">Node.js - Download Node.js®</a></p><p>b. Install Angular CLI using</p><pre>npm install -g @angular/cli</pre><p>c. Once Node and Angular CLI are installed globally on the machine, create a new Angular Project on your workspace.</p><pre>ng new ui-demo</pre><p>This command will create a new Project called ‘ui-demo’ with package.json file and install all the dependencies into the node_modules folder. Your project is ready to run on localhost:4200.</p><pre>ng serve</pre><p>This command will start compiling and run your newly created code on port 4200 on your localhost. Just go to <a href="http://localhost:4200/">http://localhost:4200</a> and you can see the page where you can see the home page of your Application.</p><p>We shall now make this demo code Production ready by typing in,</p><pre>ng build --prod=true</pre><p>This will create a “dist” folder inside our root project and has all the compressed, minified and uglified version of our Angular Application which is now ready to be hosted. Thanks to Angular for making this simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*l7bQqiq1rkJUJvDjYxWr2A.png" /></figure><p>With this, our Base Angular UI Project is created and as I said, I will not be digging deep into Angular and its components. The rest of the article will be focussing on how to host this Project on S3 Buckets using CloudFront.</p><blockquote>Step 2: Create an S3 bucket on AWS and host this code on the S3 Bucket.</blockquote><p>Logon to <a href="https://aws.amazon.com/console/">https://aws.amazon.com/console/</a> and create an account if you done have one.</p><p>Go straight to S3 buckets section and create a new S3 bucket. Choose the name of the bucket and select a region for the same. I am naming it as “ui-hosting-example” in this case. Make sure you have the “Block all Public Access” tag enabled. This is very important as we don’t want our S3 bucket to be wide open on the internet and would like to keep them private and secure. If made Public, it defeats the entire purpose with respect to code’s Security.</p><p>Below is the snapshot of S3 bucket creation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*2e6lo7hLSzuENsUHVSa8Sw.png" /></figure><p>Once the S3 bucket is created, now is the time to upload the Angular Code into the bucket.</p><p>Go to your project folder-&gt;dist-&gt;project_name and upload all the uglified files including the index.html into your S3 bucket.</p><p>Once everything is uploaded, this is how your S3 bucket should look like,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dLCL6jfWes1i6jFjU-tpww.png" /><figcaption>S3 Bucket — After code upload</figcaption></figure><p>Go to Permissions-&gt; Bucket Policy and at this time, the Bucket policy should be empty and I shall come back to this once we talk about CloudFront.</p><p>Our S3 bucket is used to host a website, so navigate to Properties-&gt;Static Website Hosting and enable the feature of “Use this bucket to host a website” and add index.html as the Index document.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Td5mWYaZsx0dZM-OD__www.png" /></figure><p><strong><em>This bucket is not public and we intend to keep it that way. I want to stress this point on our bucket being “Private” as I want to ensure our Application Security.</em></strong></p><blockquote>How to double check if the bucket is Private?</blockquote><p>Method 1: We can double check the Public/Private Access by navigating to Permissions-&gt; Block Public Access and here the “Block Public Access” should be ON.</p><p>Method 2: Go to the Overview Section of the Bucket on the main page and select the checkbox on the index.html file. A side bar on the right would popup and displays a property called Object URL. Copy paste the URL on the Browser and it should display Access Denied Page. This also ensures the bucket and its Objects are Private.</p><p>Please take a lok at the below snapshot for better understanding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8OTL7m27VZKutSW3jzp86A.png" /></figure><p>Now, with code hosted on th S3 bucket, it’s time to build our CloudFront distribution.</p><blockquote>Step 3: Create a CloudFront URL and map it to the newly created S3 bucket.</blockquote><p>Go to CloudFront on AWS Console and create a new CloudFront Distribution.</p><blockquote>Origin Settings — Key Points:</blockquote><p>Origin Domain Name: ui-hosting-example.s3.amazonaws.com</p><p>Restrit Bucket Access: Yes</p><p><strong>Origin Access Identity: Create a new Identity</strong></p><p><strong>Grant Read Permissions on Bucket: Yes,Update Bucket policy (This will take care of updating our S3 Bucket policy to read only from CloudFront as our Bucket is Private.</strong></p><p>Default Root Object: index.html (As, this is the file that we want our CloudFront to point to)</p><p>This will take some time to create the CloudFront Distribution and takes at least 3 minutes to fully deploy our Application.</p><blockquote>Step 4: Check the S3 bucket policy.</blockquote><p>I mentioned in the earlier section, that I want to revisit the Bucket Policy to ensure Security. While the CloudFront Distribution is getting created, navigate to the S3 bucket and open the Bucket Policies Section under Permissions tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JK7ub1V6HSvR27sqJhqWZQ.png" /></figure><p>The Bucket Policy is now updated with read persmissions from the CloudFront we just created. TheCloudFront is now enabled to read the S3 bucket and now our Private Bucket is opened to the internet only with the CloudFront URL and all the objects are Private.</p><blockquote>Step 5: Test the CloudFront URL.</blockquote><p>Navigate back to the CloudFront URL and once the CF status is Deployed, go to the General Tab and grab the URL under the Domain Name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*Tcfcf2JFa1mIow7ZVWZTsA.png" /></figure><p>Navigate to the URL domain name from your browser and voila..!! You can see your awesome Web Page show up on the Internet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bFNT4bR40ysGU0ppg_Lvaw.png" /></figure><p>This way you can enable Web Hosting from S3 Buckets through CloudFront URLs keeping the S3 Bucket Private. This can be enhanced further by mapping the CloudFront URL to your Route53 with your desired Domain Name. This way you can have your desired domain name point to CloudFront and thus pointing to S3 buckets.</p><p>I hope this article of mine threw some light in understanding the efficient UI deployment model and helps you in Cloud Optimization and save some money as S3 buckets are way cheaper than EC2 Instances. Happy Coding..!!</p><p>If you like this article, please do Clap hands at the bottom of the page as many times as you can. It encourages me to write more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=156838f4b287" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-efficiently-host-your-web-applications-ui-on-s3-buckets-through-aws-cloudfront-156838f4b287">How to efficiently host your Web Applications (UI)on S3 Buckets through AWS CloudFront</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blue-Green with Canary Deployment — A Novel approach]]></title>
            <link>https://levelup.gitconnected.com/blue-green-with-canary-deployment-a-novel-approach-2cee77ff564d?source=rss-248b5a922263------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cee77ff564d</guid>
            <category><![CDATA[blue-green-deployment]]></category>
            <category><![CDATA[ec2-instance]]></category>
            <category><![CDATA[blue-green-with-canary]]></category>
            <category><![CDATA[traffic-throttle]]></category>
            <category><![CDATA[canary-deployments]]></category>
            <dc:creator><![CDATA[Teja Swaroop Mylavarapu]]></dc:creator>
            <pubDate>Thu, 30 Apr 2020 01:33:30 GMT</pubDate>
            <atom:updated>2026-01-11T16:42:08.733Z</atom:updated>
            <content:encoded><![CDATA[<h3>Blue-Green with Canary Deployment — A Novel approach</h3><p>Yes, you read that right. I want to talk about the combination of Canary in conjunction with Blue-Green.</p><p>Usually, we see deployments either in Canary or in Blue-Green. Here, in this article, I would like to take out some time and talk about the prospects and possibilities of Blue-Green with Canary Deployment. I will be explaining this article using AWS terminology.</p><p>Terminology used:</p><p>a. Docker — A containerized platform to build images and run the code as containers</p><p>b. AWS Cluster — A Logical grouping of AWS Services deployed on EC2 Instances</p><p>c. AWS Services — Tasks which are responsible for the successful running of your docker containers managed by ECS.</p><p>First, let’s hit the basics:</p><blockquote><strong>What is Blue Green Deployment?</strong></blockquote><p>Blue-Green Deployment is a deployment mechanism where two identical stacks (AWS clusters) are setup in parallel called Blue and Green with only one of them taking the active traffic (Let’s say Blue for this purpose) and the other being idle.</p><p>With new Production release coming up, new code deployments will be happening on the Inactive Green cluster. Once the deployment is complete and we see that the environment is stable with all the docker containers up and running actively, the traffic via Route 53 is now systematically routed from Blue to Green, thereby making Green the new active Cluster and dethroning Blue to the Inactive State.</p><p>This approach is highly effective in Production systems which cannot afford downtime and for applications which are considered highly critical. Reversing the traffic from Green (New) to Blue (Old) is easy if at all there is a need to rollback the release due to any unforeseen issues as the older stack is readily available.</p><figure><img alt="Before: Blue as Active" src="https://cdn-images-1.medium.com/max/960/1*DxMKlnAhfkcQzNBS9vYcAg.jpeg" /><figcaption>Before:Blue as Active</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*130E16BvabhOId_UJ4T7Hw.jpeg" /><figcaption>After: Green as Active</figcaption></figure><p>The downside of this approach is the maintainability and cost.</p><p>We need to maintain 2 clusters (Blue and Green) and maintain both of them in parallel thereby doubling the cost of our Servers significantly (EC2s and ALB cost good amount of money).</p><p>One can argue with the fact that after a significant amount of observing the stability of the new deployment, the old Clusters can be deleted. This approach can be practiced, but is often considered very cumbersome and majority prefer keeping both the clusters.</p><blockquote><strong>What is Canary Deployment?</strong></blockquote><p>Canary deployment is an another style of deployment where the new deployment happens on the existing cluster with new docker containers (maybe new EC2 Instances depending on your ASG policy). The new deployment will have its own ALB with it s own Target Group. The traffic is rolled out to the users on an incremental percentage basis using Route 53.</p><p>The incremental approach reduces the risk of impact it can have on real customers.</p><p>Once the new deployment is done, the traffic is routed to the new containers on a throttling basis. Using Route 53 weighted records, we can tweak the traffic and decide to send only 10% of the traffic to the new containers using the new ALB. Once things look good, we can increase the weight on a regular basis till it reaches 100:0. Using this approach, even if something gets messed up during the throttle, we can easily rollback to the older version and ensure only a small percentage (here 10) of users are impacted with the new release.</p><p>Once the validations look good, the old containers and the old ALB including the Target Group needs to be deleted and ensure that the whole traffic is now routed to the new ALB pointing to the new containers.</p><p>This approach is advisable to applications which are not highly critical as we are throttling the traffic to the new users who might get affected. Cost is significantly reduced as there is no overhead of the old cluster. No maintenance of old ALBs or old ECS Clusters or old instances ad everything gets cleaned up after the validation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*BiH5M3pmZBitpatAOtyzPg.jpeg" /><figcaption>Canary: During Deployment</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*GmyFPBeRcoBSi9ZAV3Lr1A.jpeg" /><figcaption>Canary After Deployment</figcaption></figure><p>One major problem with this approach is Rollback. Despite of all the validations and precautionary measures we take during the Software Development Life Cycle, there are chances of systems being unstable and new features in the code blowing up on our face after a stipulated period of time.</p><p>Examples include:</p><p>i. Memory Leaks — Don’t get me started on this as there is no straightforward approach to solve a memory leak issue. There can be N number of reasons for a memory leak to happen and it usually takes days to identify and solve a memory leak issue. During this process, one might want to rollback to the older version while the problem in the new version is getting fixed. We cannot do that in Canary as the old version has been deleted.</p><p>ii. Resiliency Issues — Connectivity failures with region isolations and failing of Servers on one Region vs the other is a common issue. Despite of having Auto Failovers in place, connectivity and resiliency can sometimes be a problem.</p><p>iii. Customers not happy with the feature — This might be a rare scenario, but it can turn out that the new feature released has not met the expectations of the customer and it might prompt us to immediately rollback to the older version.</p><p>So, what is the Interim Solution: Build and deploy the older version of code and go though the whole Pipeline and release process (approvals and the scary red tape) for the old version all over again. This process can be tedious if new features are released on a regular basis.</p><blockquote><strong>What is Blue-Green with Canary Deployment all about then?</strong></blockquote><p>My idea here is to provide a simple solution where I am trying to marry both the deployment process into one.</p><blockquote>How can we do that, you ask</blockquote><p>Do not delete the old ALB and EC2 Instances once the Canary deployment is done. This way we are mimicking the Blue Green model but within the same Cluster using Canary model.</p><p>Keeping the old services (containers) will help us achieve the rollback immediately and helps us achieve what we want at a rapid pace.</p><p>This step will also help us reduce the overhead of maintaining an extra inactive cluster which we determined to be expensive on a cost basis for the pure Blue-Green model.</p><p>Still, we have a problem of EC2 instances sitting idle with old docker containers which is still easting into our wallets. We need to attack this problem by appropriately tuning our AutoScaling Groups and the memory allocation of docker containers and squeeze in as many containers as possible inside one EC2 instance.</p><p>Keeping a buffer of 20% of memory to the instance, if we are requiring 3 docker containers with 30% of memory, then we need 2 EC2 instances with one having 2 docker containers with 60% + 20% (buffer) memory allocated and the other EC2 Instance having 30% + 20% (buffer) allocated. So, we are paying for 2 EC2 Instances in total (Pure Canary approach)</p><p>Our Solution: If we can reduce the docker memory to 24% each, then we will be having 72% + 20% (buffer) memory allocated in 1 EC2 instance and now we can use the other EC2 instance to host the old code and squeeze this in the same Cluster.</p><p>To quantitatively assess the hybrid model against baselines, consider the following comparison based on key metrics derived from AWS deployments (assuming a mid-scale application with 3–5 containers and standard EC2 t3.medium instances):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*AVSx_-cqhXEGuf_gS02hwA.png" /></figure><blockquote>Experiment comparing the traditional approach vs the novel approach:</blockquote><h4>Experiment Name: Monte Carlo Simulation for Cost and Rollback Time</h4><p>To check how well the hybrid method works, we ran a basic simulation called Monte Carlo. It’s like playing out 100 pretend deployments with random changes (like varying rollout times due to traffic or builds) to get a sense of average results. We looked at costs (using EC2 server time at $0.04 per hour) and how long it takes to undo a bad update, based on these easy setups:</p><ul><li>Blue-Green: Uses two full sets of servers (twice the resources).</li><li>Canary: Uses one set of servers but temporarily boosts it by 1.5 times.</li><li>Hybrid: Uses one set of servers but smartly squeezes in 1.2 times the usage with tweaks.</li><li>Rollout time: Randomly picked between 0.5 and 2 hours, like a fair dice roll.</li><li>Undo times: Spread out like a bell curve (quick for Blue-Green and Hybrid; slower for Canary since it needs rebuilding).</li></ul><p>Before presenting the results table, here are the essential formulae for calculating the averages (means) and standard deviations from the 100 simulated runs:</p><ul><li><strong>Sample Mean (Average)</strong>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*3NUAU4IN13cdaOMtTUYglQ.png" /></figure><ul><li><strong>Sample Standard Deviation (Std Dev)</strong>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*OyJ6hKX3VhPcjkuCJ8zK_A.png" /></figure><p>This measures the variability in the simulated outcomes.</p><p>These were applied separately to the cost and rollback time values for each strategy. Costs were derived as Cost=rate×duration, with durations drawn from a uniform distribution between 0.5 and 2 hours. Rollback times were drawn from normal distributions specific to each strategy.</p><p>Here’s what we found from those 100 tests:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*5UqWdGj_4CHGRaiCuqD4Fw.png" /></figure><p>Observations from the Experiment:</p><ul><li><strong>Lower cost without sacrificing safety:</strong> Across 100 Monte Carlo rollout runs (rollout durations uniformly randomized from 0.5–2 hours at $0.04/hr), the <strong>Hybrid</strong> strategy produced the <strong>lowest average cost ($0.129)</strong> versus <strong>Blue-Green ($0.215)</strong> and <strong>Canary ($0.162)</strong> — about <strong>40% cheaper than Blue-Green</strong> — while keeping cost variability low, indicating consistent savings run-to-run.</li><li><strong>Fast rollbacks comparable to Blue-Green:</strong> The Hybrid approach maintained <strong>sub-minute rollback behavior (~0.78 min avg)</strong>, close to <strong>Blue-Green (~0.51 min)</strong> and dramatically faster than <strong>Canary (~20.0 min)</strong>, which is slower because rollback often requires rebuild/redeploy actions rather than simply reverting traffic to a retained “known-good” stack.</li><li><strong>More predictable and dependable outcomes:</strong> Hybrid showed <strong>tight dispersion</strong> in both cost and rollback time (low standard deviations), meaning performance is <strong>stable under random rollout conditions</strong> (traffic/build timing fluctuations). Practically, this makes the novel approach a strong default for teams that want <strong>near blue-green rollback speed</strong> with <strong>canary-like resource efficiency</strong> and less operational risk.</li></ul><p>Summary:</p><p>We introduced an Innovative and Practical “Blue-Green with Canary” hybrid approach that combines the best parts of both strategies: <strong>progressive exposure</strong> during rollout (canary-style traffic shifting) and <strong>rapid rollback</strong> (blue/green-style revert) by intentionally <strong>retaining the previous version’s serving stack</strong> for a short, configurable window. Instead of paying for two fully duplicated environments all the time, the approach keeps costs closer to a single environment while still preserving a safe escape hatch when late-stage issues appear (e.g., memory leaks, performance regressions, or dependency failures).</p><p>To validate the trade-offs, we ran a simple Monte Carlo simulation of 100 randomized deployments using EC2 time at $0.04/hour with rollout durations uniformly sampled from 0.5–2 hours. The results showed the Hybrid strategy delivered the <strong>lowest average cost ($0.129)</strong> compared to <strong>Canary ($0.162)</strong> and <strong>Blue-Green ($0.215)</strong> — about <strong>40% cheaper than Blue-Green</strong> — while maintaining <strong>near-instant rollback behavior (~0.78 minutes)</strong> close to <strong>Blue-Green (~0.51 minutes)</strong> and far faster than <strong>Canary (~20 minutes)</strong>. Overall, this hybrid offers a pragmatic operating model: safer rollouts, faster recovery, and better cost efficiency — without forcing teams to choose between reliability and economics.</p><p>Practically, this approach reduces the “either/or” tradeoff between reliability and cost. You avoid maintaining two fully duplicated environments for every release (typical blue/green), yet you also avoid the operational pain of slow “roll-forward” recovery when a canary fails after the old version has been scaled down or removed. The pattern fits well with modern cloud primitives (load balancers, weighted routing, autoscaling) and encourages SLO-driven guardrails (error rate, p95 latency, saturation) at each shift step, making releases more measurable and repeatable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cee77ff564d" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/blue-green-with-canary-deployment-a-novel-approach-2cee77ff564d">Blue-Green with Canary Deployment — A Novel approach</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Server Sent Events — Architecture and Implementation]]></title>
            <link>https://levelup.gitconnected.com/server-sent-events-architecture-and-implementation-d4ec3fa7974e?source=rss-248b5a922263------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4ec3fa7974e</guid>
            <category><![CDATA[browsers]]></category>
            <category><![CDATA[server-sent-events]]></category>
            <category><![CDATA[event-source]]></category>
            <category><![CDATA[sse]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Teja Swaroop Mylavarapu]]></dc:creator>
            <pubDate>Mon, 20 Apr 2020 02:47:56 GMT</pubDate>
            <atom:updated>2026-01-12T01:46:35.519Z</atom:updated>
            <content:encoded><![CDATA[<h3>Server Sent Events — Architecture and Implementation</h3><p>SSE — An interesting architecture that has been making rounds for quite some time.</p><blockquote>So, what is SSE?</blockquote><p>In layman terms, SSE is a Server Sent Event where the UI first initiates the call and requests for data, then the Server sends back the data to the caller (UI) when the data is available.</p><p>When an HTTP connection is made from the UI, the server holds the connection and responds back with the data when and ever it gets an event/data from the downstream APIs/sources.</p><p>Unlike a normal HTTP call where the Server sends back the response immediately and close the connection, in the case of SSE, the Server holds the connection for a period of time and emits back the response as Streams when it’s available. It can send packets of data as a stream one after the other with a single HTTP Connection. Once all the data is sent, the Server then closes the connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*DmvGvHrjHf2k4lCFCV0YOQ.jpeg" /><figcaption>Image 1. Server Sent Events Request-Response Diagram</figcaption></figure><p>As depicted in the diagram above, the Server sends the responses as a Stream of data in the form of Flux. One single request from the Browser will emit multiple responses (JSON type) back in the same HTTP (HTTPS) call.</p><p>The Browser however has to implement the request as an EventSource Object from JavaScript. This Object is present in all the major browsers by default except for Internet Explorer (I know what you feel about this…!!).</p><blockquote>Why Server Sent Events?</blockquote><p>Server Sent Events (SSE) are used in scenarios where the browser constantly looks for updates from the Server and the Server emits out the responses when and if anything is available on its side. Instead of the Browser making continuous requests (Long Polling) again and again, the Browser just makes 1 request and the Server sends back the response/responses whenever it is available.</p><p><strong>Long Polling Scenario:</strong> If the Server does not have the data available when the Browser request comes in, usually it sends back empty data and the Browser makes the request again after some time to check if the data is available and the server responds appropriately and this loop can go on forever if the Server does not have the data.</p><p>Trust me, I have seen around 25–30 Round Trip calls being made in these scenarios where the Browser constantly kept checking for updates on the Server with no luck. This scenario is pretty draining and proves to be very cumbersome on the Browser’s resources with multiple calls being made repeatedly.</p><p>The architecture and SSE completely eliminates the concept of Long Polling where the Browser keeps making multiple requests to the Server.</p><p>Now, with a basic understanding of what is SSE, let us dig a little bit on the coding perspectives and how this can be achieved.</p><p>Tech Stack used:</p><ol><li>JavaScript for the UI</li><li>Java for the Backend</li><li>Apache Kafka as data consumer</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*2HBWED_On_v6ZfeHlTK94A.jpeg" /><figcaption>Image 2: Real time SSE Implementation</figcaption></figure><blockquote>SSE Implementation:</blockquote><p>Step 1: <strong>JavaScript for Browser</strong></p><p>A Browser makes the call to the SSE Server through the <strong>EventSource Object. </strong>EventSource Object is the JavaScript implementation of SSE. With an EventSource Object, the browser makes the call to the Server and holds on to the call till the Server terminates the call. For any reason (ALB Timeout, Network disruption), if the connection from the UI to the backend breaks, the EventSource object automatically reconnects to the Server. Let me tell you, this is automatic, no extra manual or coding intervention needed.</p><p>JavaScript Snippet for SSE:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*6ORwKFgjzVpzic59nmQ5SQ.png" /></figure><p>Step 2: <strong>SSE on the Server (Java)</strong></p><p>a. SSE events are sent back in the form of Streams. So we have to make sure that our code/API responds back with the response type as “text/event-stream”.</p><p>b. SSE is implemented based on the connection from the UI. When a connection request comes in, the Server needs to hold on to the connection till a response is obtained. It can be implemented in Java using “EmitterProcessor”. It is a type of processor that can be used with several subscribers. This EmitterProcessor is the processor which holds the unique one time connection with the Browser.</p><p>c. The response type of the data sent back to the Browser is of type Flux. Flux is the object that is responsible in streaming the data back to the user.</p><p>Both Flux and EmitterProcessor are built on Java’s Reactor core Publisher API. <a href="https://github.com/reactor/reactor-core">Reactor Core</a> is a Java library which implements the reactive programming model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zw_sK7mZ6-2zybYI8aouyg.png" /></figure><p>The above code depicts on how the GET call is built in Java and how the response type is of event-stream value, the connection received and the Flux events getting sent back to the caller (Browser).</p><p>Step 3: <strong>Kafka Consumer, sending SSE events</strong></p><p>Once the connection is established, the Server holds the connection and waits for data. Here, we are reading the events from an Apache Kafka Consumer. Once the Kafka Producer produces an event for the topic which our Kafka Consumer subscribed, the data/events will be consumed by our Consumer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*emaE_dM5sMkKOCLoJz32AA.png" /></figure><p>The data is read and if there is an SSE connection that exists, the data is emitted back to the Browser. This process is repeated till the Server terminates the connection.</p><p>Things to be aware of:</p><p>While using AWS, the connection from the Browser to the Server gets disconnected based on the Application Load Balancer’s (ALB) timeout. If the timeout is configured for 180 seconds, the connection gets disconnected after 180 seconds and the browser automatically reconnects to the Server.</p><h3>Evaluation: Long Polling vs SSE (Micro Results)</h3><h3>Goal</h3><p>We compare <strong>Long Polling</strong> and <strong>Server-Sent Events (SSE)</strong> for delivering near-real-time updates from the server to the browser. The goal is to quantify differences in:</p><ul><li><strong>Request volume</strong> (network and server overhead)</li><li><strong>Update latency</strong> (how quickly the UI reflects new data)</li><li><strong>Operational stability</strong> (connection behavior under load)</li></ul><h3>Workload / Assumptions</h3><p>We evaluate a simple streaming workload:</p><ul><li><strong>C clients</strong> concurrently viewing the page (example: <strong>C = 500</strong>)</li><li>Server generates or consumes events at <strong>1 event/second</strong> (Kafka topic or internal publisher)</li><li>Long polling uses a fixed polling interval <strong>T seconds</strong> (example: <strong>T = 5s</strong>, plus a sensitivity case <strong>T = 1s</strong>)</li><li>Events are assumed to arrive uniformly over time</li></ul><blockquote><em>Note: The “Results (Analytical)” table below is </em><strong><em>computed</em></strong><em> based on the properties of polling vs streaming. It does not require any benchmark tooling and is useful as a baseline expectation.</em></blockquote><h3>Metrics</h3><p><strong>Requests per minute (RPM)</strong></p><p>Long Polling:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*2CXCMuoSeT3kEkjBjREV7Q.png" /></figure><p>SSE: approximately <strong>C initial requests</strong> (one per client to open the stream) plus occasional reconnects.</p><p><strong>Update delay (seconds)</strong> from “event available on server” → “event visible to browser”</p><p>Long Polling delay is bounded by the polling interval <strong>T</strong>. If events arrive uniformly, delay is approximately uniform between <strong>0 and T</strong>:</p><p>Average delay ≈ <strong>T/2</strong></p><p>p95 delay ≈ <strong>0.95T</strong></p><ul><li>SSE pushes updates immediately when available; delay is dominated by <strong>network + server processing</strong> (typically much lower than seconds, often sub-second).</li></ul><h3>Results (Analytical / Computed)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*sTrw7ki_lhiwG6HBSgQbkA.png" /></figure><p><strong>Interpretation:</strong></p><ul><li>Long Polling creates a <strong>linear explosion in HTTP requests</strong> as you decrease T to improve responsiveness.</li><li>SSE achieves <strong>low latency without increasing request rate</strong>, because the connection stays open and events are pushed over the same stream.</li></ul><h3>Practical Applications of SSE on where it can be implemented in today’s industry:</h3><h4>1) Cross-device state sync (Mobile action to Desktop updates instantly via Kafka + SSE)</h4><p>When a user completes a step on <strong>mobile</strong> — for example uploading an ID, finishing OTP/MFA, or submitting verification — the <strong>desktop session</strong> should reflect that immediately without refresh. A clean approach is: the mobile workflow publishes an event to <strong>Kafka</strong> (ex: verification.completed) containing correlation keys like userId/sessionId and the new status. The desktop web app opens an <strong>SSE</strong> stream to your backend. On the server, a Kafka consumer reads the relevant events and pushes them over SSE (event, id, data) to the browser, which updates the UI from “Waiting” to “Verified”. For production readiness, scope the SSE stream with strong auth, filter events by user/tenant, include heartbeats to prevent idle timeouts, and use Kafka offsets + Last-event-ID for safe resume after reconnects. This creates seamless cross-channel continuity and reduces customer friction.</p><h4>2) Real-time operational dashboards (Service health, incidents, deployments, fraud alerts)</h4><p>Dashboards often struggle with either stale data (slow polling) or heavy traffic (fast polling). SSE provides low-latency updates with a single long-lived connection per viewer. In this pattern, backend systems publish operational events and metrics to <strong>Kafka</strong>. A dashboard backend consumes these topics, optionally aggregates by environment/team, and streams updates to browsers via SSE endpoints . The UI updates charts, tables, and alerts immediately when new events arrive—avoiding the “thundering herd” effect of many clients polling at the same time. To harden it, add keepalive comments/heartbeats, handle client reconnects gracefully, and etc so viewers don’t miss key updates during network blips. This yields smoother operations, faster response, and predictable server load.</p><p>There are many such examples where we can leverage SSE Protocol and Architecture leveraging various Infrastructure Components.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4ec3fa7974e" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/server-sent-events-architecture-and-implementation-d4ec3fa7974e">Server Sent Events — Architecture and Implementation</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>