<?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 Munsif Musthafa on Medium]]></title>
        <description><![CDATA[Stories by Munsif Musthafa on Medium]]></description>
        <link>https://medium.com/@munsifmusthafa03?source=rss-7a60efe554cd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LyKjo6GwNQjhxhZWNB5AxA.jpeg</url>
            <title>Stories by Munsif Musthafa on Medium</title>
            <link>https://medium.com/@munsifmusthafa03?source=rss-7a60efe554cd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 05:24:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@munsifmusthafa03/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[Circuit Breakers: the What and the Why?]]></title>
            <link>https://medium.com/@munsifmusthafa03/circuit-breakers-the-what-and-the-why-6749bda0be98?source=rss-7a60efe554cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/6749bda0be98</guid>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[network]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[circuit-breaker]]></category>
            <dc:creator><![CDATA[Munsif Musthafa]]></dc:creator>
            <pubDate>Wed, 29 Jun 2022 12:16:21 GMT</pubDate>
            <atom:updated>2022-07-02T14:46:26.122Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine there’s a huge line at the gas station ⛽. The attendant takes a few minutes per vehicle to pump fuel and there are only a handful of pumps and attendants. Now more and more vehicles are joining the queue awaiting their turn and eventually gas runs out at the station. Those who waited for so long would probably stay there until the station is able to refuel the vehicle. This wastes valuable time for the consumers.</p><p>Let’s try to apply the same story to the world of microservices.</p><h3>Problem</h3><p>In the modern world of distributed computing, there are possibilities of different failures to user workflows like slow network connections, timeouts, overcommitted resources, and complete server shutdown due to unanticipated events. Some of these would typically correct themselves after a short period of time, but some might take longer and even require human intervention to get back up and running.</p><p>Cloud applications are typically expected to be robust and resilient, so it’s ideal that a <strong>Retry</strong> mechanism and/or a <strong>Circuit breaker</strong> is in place to provide a highly available service to the consumers. For transient issues where the service getting invoked would have resolved the issue itself, the retry pattern makes sense. But in case the service has completely gone down, it would be pointless to keep invoking the same; this is where a circuit breaker would come into play.</p><p>For example, there is SERVICE_A that speaks to SERVICE_B to get something done for a customer flow. In case of an <strong>immediate</strong> <strong>failure</strong>, the service would return an error and, the resource — <strong>thread</strong> that was allocated for this task is <strong>immediately released</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*pZCvdGx95O4G65QGnTqkeQ.png" /><figcaption>Image 1: Immediate failure. Resource released</figcaption></figure><p>In case of a <strong>timeout</strong> occurrence, SERVICE_B takes a long time to respond back to SERVICE_A. Here SERVICE_A would have already <strong>dedicated a thread</strong> from the thread pool for this network call which now <strong>keeps waiting</strong> for a response back. If another request flows through, similarly another thread will be allocated. In case the rate of requests to SERVICE_A is really high, then eventually all the threads are going to wait for a response from SERVICE_B. In this, a failure in SERVICE_B has caused a failure in SERVICE_A, and in a connected distributed environment, this has an ugly <strong>cascading</strong> effect that will impact actual business.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*ga6EJ91tpQwGa2883Apq4g.png" /><figcaption>Image 2: Timeout failure. Resource hang</figcaption></figure><h3>Solution</h3><p>To address this issue the first step is to note that there’s a failure in SERVICE_B and <strong>stop calling</strong> it. This will allow the recovery process for the service. Then we should <strong>return a default response</strong> that can allow the customer flow to continue. Eventually, it&#39;s the business that we are trying to save.</p><h4>Allow Calls</h4><p>To achieve this, we would need an interceptor through which all the calls from SERVICE_A to SERVICE_B would flow through. This interceptor will act as the gatekeeper who evaluates the request and responses to determine whether the SERVICE_B is healthy or not. This will <strong>maintain the evaluated states</strong> within itself. When SERVICE_B works as expected and returns responses within the allocated time, then the status will be a value similar to ALLOW.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*Ce_4Y0YZz3toptCIj5VJSg.png" /><figcaption>Image 3: Request interceptor. Success response. Allow status</figcaption></figure><h4>Deny Calls</h4><p>When SERVICE_B does not respond as expected, shows concurrent failures, or takes a long time to respond to each query, then the status will be set to a value similar to DENY. But it wouldn’t be ideal if for a single failure this status changes from ALLOW to DENY as mentioned earlier, intermittent failures are expected in distributed systems. Circuit breakers are smart enough to evaluate this based on the behavior of the service (along with some configurations of course), over a period of time or over a number of requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*Ru0drhmcg0A95iwTeh_iuQ.png" /><figcaption>Image 4: Request interceptor. Failure response. Deny status</figcaption></figure><h4>Allow Limited</h4><p>There are a few attributes that a circuit breaker would maintain such as the number of calls that failed due to errors, the number of calls that failed due to timeouts, the number of calls that were not permitted to pass through during denied state, the thresholds for which the circuit would trip, and others.</p><p>So for example, there are 10 concurrent calls that came from the client to SERVICE_A which are intended to reach SERVICE_B. Out of the 10, the first 4 succeed, and then the next 6 fail due to errors. If we have the threshold for the circuit to trip at 50% of total requests failure, then it’s going to determine that there has been a failure rate of 60% (as 6 out of 10 requests failed). This will transition the state of the circuit breaker to DENY. During this period, there would ideally be a default response sent back to the client from SERVICE_A, ideally.</p><p>Following this, SERVICE_A will stop calling SERVICE_B for a designated time, allowing it to recover. If we assume the waiting period is 30 seconds, after the 30 seconds the next set of requests will be passed down to SERVICE_B. But we can’t be really confident that SERVICE_B has fully recovered. So only some calls will be allowed to pass and the circuit breaker would re-evaluate based on the response from SERVICE_B. This is a special state that has a value similar to ALLOW LIMITED.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*-vd6J54zGqMQHY_0QcyQ1g.png" /><figcaption>Image 5: Request interceptor. Limited requests to downstream service. Allow limited status</figcaption></figure><p>If during this period, all the requests sent out have a predefined percentage of success rate (it could be the same rate as above), then the circuit will change the state to ALLOW. But if the service hasn’t fully recovered and some calls fail, then again based on the threshold, the circuit will trip to DENY state. This whole cycle of evaluating and tripping the circuit is the core of the Circuit Breaker pattern.</p><h3>Circuit Breaker States</h3><p>In an electrical circuit, if the circuit is closed, electricity flows through it. In the microservices context, the servers start up with the circuits in the <strong>CLOSED</strong> state, allowing the proper flow of network calls. If there are unintended issues in a circuit and the proper flow of electricity cannot be maintained then the breaker will trip and open the circuit. Similarly if due to undesired issues there are failures with the network calls and the number of failures exceeds the defined threshold, the circuit will be transitioned to the <strong>OPEN</strong> state, prohibiting calls from flowing downstream. To avoid human intervention in fixing the opened connection, circuit breakers have a timer after which runs out, the opened connection will be partially closed allowing for some requests to flow through. This state is called the <strong>HALF_OPEN</strong> state in the microservice world which allows only a few calls to flow through and inspect if the dependent service is working as expected. As explained above, during this phase, if the service isn’t online, it will flow back to the OPEN state and the whole thing runs in a cycle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*t6Rxq8KNdJqSN9LY329mSg.png" /><figcaption>Image 6: States of a circuit breaker</figcaption></figure><p>I would not go into implementation details and code in this blog. So to give a general idea, this is how the code would look being “decorated” by the circuit breaker code. I shall meet you in another blog to give a practical way of implementing this in your microservices. Ciao!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*3H_VL8NDAHa1dzwq052A8w.png" /><figcaption>Image 7: Decorated code block</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6749bda0be98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[If you are travelling from Sri Lanka…]]></title>
            <link>https://medium.com/@munsifmusthafa03/if-you-are-travelling-from-sri-lanka-9bed58fae997?source=rss-7a60efe554cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bed58fae997</guid>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[dubai]]></category>
            <category><![CDATA[credit-cards]]></category>
            <category><![CDATA[visa]]></category>
            <category><![CDATA[sri-lanka]]></category>
            <dc:creator><![CDATA[Munsif Musthafa]]></dc:creator>
            <pubDate>Thu, 16 Jun 2022 14:26:35 GMT</pubDate>
            <atom:updated>2022-06-16T14:26:35.806Z</atom:updated>
            <content:encoded><![CDATA[<p>This is going to be a narration of why and how I travelled <em>from </em>Sri Lanka during inflation.</p><p>Most of you might know that Sri Lanka (motherland) is going through a difficult economic crisis. This happened due to corrupt politicians and mismanagement of wealth. Inflation is running wild on the graph.</p><h3>During such an economic crisis why did I decide to go for a week-long trip?</h3><p>Due to inflation, our any and all savings have lost their value by 45–60% within a short span. Personally, this opened up my eyes to the fact that during inflation there is no point in keeping money in a savings account (this isn’t financial advice). If the government’s mismanagement is going to rip me off of my savings, at least I can consider this an opportunity to gain some experience. This was my thinking since I didn’t have enough money to invest in a non-depreciating property.</p><p>I did my own fair bit of research on where to go which won’t break my bank. Dubai was at the top of the list considering other personal facts (which I won’t bore you with) ✈️.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*R9rZbMOPGHkZFarU.jpg" /><figcaption>[Ref: <a href="http://www.businessnews.lk/2020/04/30/special-flight-departs-bring-back-sri-lankan-students-from-kolkata-today/">Sri Lankan airlines plane</a>]</figcaption></figure><h3>What was the process?</h3><p>You would need 4 main documents if travelling to Dubai from Sri Lanka.</p><ol><li>Visa</li><li>Travel Insurance (due to covid)</li><li>Ticket (round-trip)</li><li>Covid vaccination certificate (at least 2 doses)</li></ol><h4>Visa + Ticket</h4><p>I physically visited and also had virtual discussions with multiple travel agencies in Colombo, to get the visa. After several calls, I had to go with a contact of a close friend to get a good deal that supported Sri Lankan Airlines. If you’re applying for a visa, you definitely have to pay for the travel insurance as well these days thanks to covid-19 😷. I also got the same party to purchase the tickets as well. All of this took <strong>3–4 days</strong>.</p><p><em>Please keep in mind that due to the current economic situation in Sri Lanka, tourist visas to Europe are getting rejected even if you produce all the required documents (which happened to a few of my friends).</em></p><h4>Vaccination certificate</h4><p>Then I applied for the e-vaccination certificate to prove that I’m vaccinated. This can be easily done using this website [<a href="https://covid-19.health.gov.lk/certificate">https://covid-19.health.gov.lk/certificate</a>] if you have the required documents. This can take from mere <strong>15 minutes to 3 days</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mx2UEViOEZS8wLEQ1rzWAQ.png" /><figcaption>Smart Vaccination Certificate online portal</figcaption></figure><h4>Money</h4><p>Next up you have to think of how and what you’d spend while travelling. Again, due to the current foreign currency shortage in Sri Lanka, banks have enforced restrictions on your accounts for overseas usage. One way I overcame this was to have multiple accounts in multiple banks. For example, BANK_A restricts you to only 75k LKR and BANK_B restricts you to only 50k LKR <strong>per week</strong>. Collectively you have a reasonable amount. My suggestion is to have at least <strong>3 useable cards </strong>💳<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*FqR7qE7sqABTRH0H.jpg" /><figcaption>[Ref: <a href="http://s3.amazonaws.com/themorning-aruna/wp-content/uploads/2021/07/02070638/1-24.jpg">bank cards</a>]</figcaption></figure><p>Along with the card transaction restriction, banks have a hefty forex charge per transaction and other miscellaneous costs. So it’s obviously good to do cash transactions. I went to the travel branch of a local bank and asked for foreign currency by showing proof of my travel. Unfortunately or fortunately they had only US Dollars and Euros of which I opted for the USD 💵. This also came with a restriction that only 1000 USD will be provided for a week-long visit. Of course, this wasn’t enough, so I spent half a day running around in Colombo to authorized money exchanges to get some foreign currency. None of them had Dirhams (AED) and most had USD but refused to give stating random reasons. When I was about to give up, I found a place which gave out a good deal on the USD exchange. For those of you who don’t know, these people deal USD in the black market while having their legal storefront as a facade. This is why the rates are very inconsistent across exchanges.</p><h4>Luggage</h4><p>The next step was to buy luggage. I compared the sky-high prices here against the prices in Dubai, and my immediate thought was that I’ll take smaller luggage just enough to hold my clothes and electronics and buy another, in Dubai if needed, and that’s what I did. Following that, I pre-booked a cab for my ride to the airport.</p><h4>Itinerary</h4><p>Definitely, definitely, make a travel itinerary. This helped me a long way to keep track of the documents, what I needed to bring from home, which places I needed to check out and what to buy there, all within the short one-week span I had allocated. And an interesting fact I knew from a friend was that I could book seats on the plane and so I did. You have to log into the Sri Lankan Airlines website [<a href="https://www.srilankan.com/en_uk/lk">https://www.srilankan.com/en_uk/lk</a>] and in the <strong>“Manage Booking”</strong> section, type in your <em>Last name</em> and<em> Booking reference</em> as in your ticket. I booked a window seat for both my trips and the view was astounding. It was actually my first time mind you😁.</p><h3>Leaving Sri Lanka…</h3><p>This was relatively a straightforward process. It’s good etiquette to arrive at the airport at least 3 hours before your flight time. But in addition to that, with the civil unrest that existed during the week of my trip, I got the cab to arrive about 5 hrs earlier 🚕. Remember to always have some change in cash to pay for the taxi.</p><p>Once you enter the airport, keep an eye on the schedule on the screens. They had already started the check-in process (weirdly) 5 hrs earlier that day and I immediately went in, past the scanner and the checkpoint. Following that, I chose to do a manual check-in where they verify your documents (the 4 I mentioned above) and I checked in my luggage. Then I filled out the exit form which was really tiny, mentioning my flight number, home address, destination and passport number. Then it’s the emigration counter. Some people scare you that they would detain if you look at them wrong even. It isn’t like that, and they seemed friendly enough and asked me the purpose of the visit and duration and stamped on my passport.</p><p>Then I had a tour around the duty-free shopping area. Spoiler: Everything was really expensive. I strolled around looking at the aeroplanes and then I realized my phone battery was draining and was looking for a charging port. Surprise surprise, there was only one charging station for the whole area and it had only 2 ports and one of them was kinda loose. I had a discussion with a foreigner there who sounded so disappointed at the state of our airport. Unfortunate actually 😥. My flight duration was 4 hrs and 45 mins and it was on time.</p><h3>When coming back…</h3><p>I have to take a bit to explain what happens at the Sri Lankan airport. Right as you descend and go through immigration and get the seal of return in your passport, you get to the conveyor belts with your luggage. It took a lot longer for everyone’s stuff to come through than I had imagined. Following this, you have to walk through the Customs check.</p><p>I might have walked or looked funny because I was stopped and asked to step into the declaration section. One thing that annoyed me was the fact that nearly 5 “officers” asked me the same questions back to back — how long was your stay and what’s in your luggage. “Dude, you have a huge scanner, why don’t you scan what’s in my luggage than annoying an already vexed traveller? 😣” — this was running in my head. Their way of “checking” was not very efficient nor effective, to be honest. I gave them straight answers and they understood there was nothing sus my luggage and let me go. For anyone wondering, I did bring an infrared stove top, an emergency lamp and some chocolates. Don’t be afraid just be clear and direct with your speech, and you have nothing to worry about.</p><p>I wish I had a medium to tell my whole story because this was a lifetime experience. This was indeed my first time alone abroad and I had to do everything on my own (of course I had some guidance from a friend and had to research some things). If this even helps out a single person, I’ll be more than happy 😌.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bed58fae997" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embark to Understand — Life Cycle of a Business]]></title>
            <link>https://medium.com/@munsifmusthafa03/embark-to-understand-life-cycle-of-a-business-335a7aa44e9?source=rss-7a60efe554cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/335a7aa44e9</guid>
            <category><![CDATA[industry]]></category>
            <category><![CDATA[business]]></category>
            <category><![CDATA[growth]]></category>
            <category><![CDATA[netflix]]></category>
            <category><![CDATA[amazon]]></category>
            <dc:creator><![CDATA[Munsif Musthafa]]></dc:creator>
            <pubDate>Mon, 22 Nov 2021 15:03:44 GMT</pubDate>
            <atom:updated>2021-11-22T15:03:44.017Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embark to Understand — Life Cycle of a Business</h3><p>Most things in the world have a cycle of life that is inevitable. Similarly, industries also go through a life cycle of their own. Exceptionally, some industries don’t adhere to a life cycle, like the food and clothing industry as it is very unlikely that they would face a decline. This blog is a continuation of my previous, <a href="https://medium.com/@munsifmusthafa03/embark-to-understand-strategy-of-a-company-d6f2dbbd78a6">on understanding various strategies a company adheres to</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nWoiNAxvRYxkpDYT" /><figcaption>The life cycle of an industry: [<a href="https://i2.wp.com/www.business-to-you.com/wp-content/uploads/2020/12/Product-Life-Cycle-1024x642.png?ssl=1">Link</a>]</figcaption></figure><h4>There are <strong>4 generally distinguished stages</strong> of the life cycle,</h4><ol><li>Introduction — Grow consumer awareness. Breakthrough technology</li><li>Growth — Focus on revenue, more resources. Fighting for competition</li><li>Maturity — High competition. Differentiation and Selecting a niche</li><li>Decline — Competing industries surpass</li></ol><p>There exist strategic importance in these phases and how companies make choices based on them. Key points to note are that each industry has its own trajectory that dictates how long each phase lasts, hence the speed of the life cycle varies from industry to industry.</p><p>Proficient managers understand the trends around this and exploit them to make a positive outcome for their industry. In a perfect business, they would <strong>enter a market in its growth period</strong>, will <strong>compete through to maturity to see cashflow increase</strong>, and look for better <strong>newer opportunities when the business starts to enter the decline</strong> phase. The life cycle models facilitate the understanding of the environment which constantly changes, and need to adapt their strategies for survival.</p><h3>Introduction phase</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Q7eRSeJ9LIzcBDPW.jpg" /><figcaption>Inception: <a href="https://thumbs.dreamstime.com/b/small-plant-growing-garden-sunlight-137371294.jpg">[Link]</a></figcaption></figure><p>The infancy of industry has some general aspects as listed below,</p><ul><li>Low industry awareness among consumers</li><li>Technological uncertainty</li><li>High capital needs</li><li>Low levels of competition</li></ul><p>There are <strong>2 main ways to approach this</strong> phase,</p><ol><li>Participate from the very beginning and be a pioneer</li><li>Enter later as a late adapter, when a market for it is created</li></ol><p>Which approach makes you a better manager if one is to ask; there is no right or wrong answer. There are benefits that exist in both of the approaches.</p><h4>Let’s take a look at the benefits a pioneer gains,</h4><ul><li>Would be able to put together a team that is actually motivated by the idea of something that doesn’t exist yet, and not by monetary needs</li><li>Would be able to gain more knowledge by getting their hands dirty and by their own experiences</li><li>Would be able to even patent their ideas and products to further incentivize</li></ul><p>A commonly discussed first mover who gained the biggest advantage is Amazon. In the bookstore world, Amazon was tiny compared to the gigantic Barnes &amp; Noble (B&amp;N) back in the 90s. Amazon pioneered online bookselling whereas B&amp;N concentrated more on having big chain retail book stores. In 1996, when Amazon had only revenue of $16 million, B&amp;N had revenue of $2 billion. Today, Amazon has nearly 50% market share for printed books compared to B&amp;N 20%, and <strong>guess what</strong>, the online E-Book share of Amazon is around 85% while B&amp;N is only at a measly 2% [<a href="https://www.axios.com/barnes-and-noble-book-stores-sale-amazon-effect-4f2753d2-818c-49d1-878a-60f0c3a5b3f7.html">link</a>]. Amazon did all of this by adapting selling on the internet, growing its product offerings, developing advanced algorithms to rope more people in, specializing in logistics, and enhancing its ability to manage huge inventory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*RXY2vzCdE_3L-FWx.jpg" /><figcaption>Barnes&amp;Noble vs Amazon: [<a href="https://imagesvc.meredithcorp.io/v3/mm/image?url=https%3A%2F%2Fstatic.onecms.io%2Fwp-content%2Fuploads%2Fsites%2F6%2F2014%2F08%2Fbarnes-noble-amazon.jpg">Link</a>]</figcaption></figure><p>On the contrary, there are other companies who were late entrants to the game and have gained a significant advantage. Below are some major downsides of being a pioneer and why it is considered risky,</p><ul><li>It is almost always unprofitable, considering the costs of research &amp; development, and marketing</li><li>Technological uncertainties like a new better technology could emerge from somewhere before the product we market is perfected</li></ul><h4>Late entrants gain these advantages in contrast,</h4><ul><li>Will be able to monitor the industry in the introduction phase</li><li>Wait till the pioneers create awareness (of the product) and a customer base is created</li><li>Exploit the mistakes of the first-movers and add aggressive marketing to overpower existing players</li><li>Possibility of a merger/acquisition with a pioneer company</li></ul><p>A good example of a late entrant is Dell beating out IBM in the late 90s. In a fair point, IBM too was a late entrant to the personal computer market compared to Apple and captured the market in the 80s. Dell and Compaq tried to individually refine the way the personal computer world operated. Compaq went for a cost-reduction technique by changing the manufacturing process and having better logistics. Meanwhile, Dell learned from both of these companies (IBM and Compaq) and built better personal computers at a reduced cost by efficient manufacturing and logistics. Furthermore, they also managed to introduce a direct-to-user channel which allowed the common folks to engage directly (around this time the client awareness around the product was high). IBM was not able to quickly react to these changes and unfortunately lost its market lead in the late 90s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U5ZkJ1Bd-WLLzzVr.jpg" /><figcaption>Dell vs IBM: [<a href="http://www.businesskorea.co.kr/news/photo/201405/3279_4626_0.jpg">Link</a>]</figcaption></figure><p>Something to also note is that the first-mover advantage is not always the best case and there are many debatable cases as above that prove late arrivals also have their own case and advantages:</p><blockquote>We have found that the differences in outcome are not random — that first-mover status can confer advantages, but it does not do so categorically. Much depends on the circumstances in which it is sought.<br>- <a href="https://hbr.org/2005/04/the-half-truth-of-first-mover-advantage">[Harvard Business Review]</a></blockquote><h3>Growth phase</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*qTEj7gJISFWofvUY" /><figcaption>Growth: [<a href="https://media.istockphoto.com/photos/hand-watering-young-plants-in-growing-picture-id1126962479?k=20&amp;m=1126962479&amp;s=612x612&amp;w=0&amp;h=oJyPkGQGCDVHjeGVFv8FmeP3xfSnekREfOSY4QfjBYA=">Link</a>]</figcaption></figure><p>Once the introduction phase is over, an industry would enter the growth phase. This is where there are only a very few players in the market, and companies can charge higher for their products, as customers would still be inconsiderate of the prices. Companies tend to cover their initial investments swiftly using this technique. A side effect of these high charges is that it makes the industry really attractive to more players. So a summary is that <strong>sales would grow</strong> in this phase <strong>and profits follow the same</strong> pattern and leading to <strong>increased competition</strong>.</p><p>As we know, the higher the competition means trying to win a bigger portion of the market share. Companies approach this in several ways including,</p><ol><li>Spending on advertising, trying to increase their brand popularity among existing and new customers</li><li>Investing more in production capacity. This results in something called “Economies of scale”. That is, <strong>Higher production capacity</strong> generates <strong>More units </strong>which result in <strong>Lower unitary cost</strong>.</li><li>Expand to the international market. Thanks to globalization, when a company does well somewhere, more often than not consumers from other parts of the world would have heard of it and want to try the products.</li></ol><p>This stage is also where the environment becomes a <strong>seller’s market</strong>, which means that the <strong>buyers for the product are in abundance, but there aren’t enough of the product to go around</strong>. Doing all the above and more would mean that a company can secure a higher market share and make it a profitable business.</p><h3>Maturity phase</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hJnBZgQBG9BQfzIS.jpg" /><figcaption>Maturity: [<a href="https://iowaee.org/wp-content/uploads/2018/04/bigtreecrop.jpg">Link</a>]</figcaption></figure><p>The maturity stage is up next in the cycle. This phase can also be comprised of the Shakeout period (rather than a stage). In short, the shakeout period is where managers would first observe the slowness of growth and try to shift the focus towards cost reduction. So let’s take a look at what characterizes the maturity stage,</p><ul><li>All well-known companies would have entered the market</li><li>There is a very dominant product design</li><li>As customers have gotten to know the industry, they’re also aware of and interested in different brands</li><li>Sales would reach a peak point and would resist further growth</li></ul><p>All of the above would result in remarkable competition amongst the key players.<strong> For somebody to gain a bigger market share, someone else has to lose theirs</strong>. The direct impact is lower product prices for a standardized version of the product agreed upon by a majority of companies, adversely resulting in lower profit margins.</p><p>This is the prime period where <strong>consolidation between companies takes place</strong>, where 2 (or more) companies operating in the same domain form an alliance,</p><ul><li>To have a better competitive position in the industry</li><li>Allowing them to use the same channels of distribution</li><li>Consolidate their marketing efforts</li><li>Reduce redundant costs by merging and using only a single department for each level such as finance and top management</li></ul><p>It is typical during this stage for companies to look into cost optimization and process improvement techniques to increase profits and to persist competitively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kdKN0Rx2M5o5hXak.jpg" /><figcaption>Kellogg’s cereal: [<a href="https://h5j4s3b8.rocketcdn.me/wp-content/uploads/2018/06/CornFlakes_CI2.jpg">Link</a>]</figcaption></figure><p>A good example of a mature market is the breakfast cereal industry. Companies like Kellogg’s, Weetabix, Quaker Oats and Nestle have experienced a slow and nearly flat rate growth in sales in the last few years. Market penetration for promoting cereal for breakfast has been done a long time back now. Since people have been having cereal-type food for breakfast for decades now, the competing companies only do brand-oriented advertising to convince their brand is better than the rest, than to promote the idea of breakfast cereal. Kellogg’s only has to convince the mass that their cereal is the best combination of quality and price. Moreover, in the year 2000, Kellogg’s acquired Kashi, which is another competing cereal company that targeted health-conscious cereal consumers. This allowed Kellogg’s to expand its sales and product portfolio, synergize its costings and marketing, as well as capture another niche market within the industry.</p><h3>Decline phase</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/0*KzPajWUyTIIQC6b0" /><figcaption>Decline: [<a href="https://live-production.wcms.abc-cdn.net.au/500f4d6c380759cae4e7c7c9c019a89b?impolicy=wcms_crop_resize&amp;cropH=2001&amp;cropW=3000&amp;xPos=0&amp;yPos=0&amp;width=862&amp;height=575">Link</a>]</figcaption></figure><p>Unfortunately, many industries experience this phase. This is characterized by the fact that there has been an absolute decrease in sales for 3 or more years. The customers who were once accustomed to certain things leave the market due to changing environment, changing tastes and trends or a new industry that is emerging.</p><p>Companies that sold 100k of an item per year would now have to sell 70k or less. This would result in overcapacity due to large plants that can produce at a high rate, which won’t be used to their fullest potential. As a result, the unitary cost will start getting higher and higher and drive down the profits lower. To counter this, some companies would sell their products at a record discount which could inadvertently affect those with inefficient cost structures due to negative margins. The companies with inefficient cost structures would be the first to abandon the industry. Bigger scale companies tend to hold on a little longer until a new industry with some good growth potential is seen.</p><p>There are <strong>4 ways how companies deal with</strong> the decline,</p><ol><li>Abandon the market immediately and disinvest in the assets. Taking this would save some moderately-sized companies from going bankrupt.</li><li>Use the harvesting strategy. This is where the managers take the decision to reduce investments and expenditures in capital expenditures, marketing and research &amp; development, and only focus on cash-flow generation.</li><li>Be bold and win back the lightly abandoned market. This would allow that company to become the market leader by acquiring the other companies market share. Simply investing a bit more in marketing would do the trick.</li><li>Executing a niche strategy. Target a very specific subset of customers by narrowing the category that the business operates in.</li></ol><p>An industry that has reached the decline phase is DVD (VCD, cassette) rental. Blockbuster, a giant in the industry who once owned over 9000 stores in the US [<a href="https://www.businessinsider.com/the-rise-and-fall-of-blockbuster-video-streaming-2020-1">link</a>], is now a classic example of managers not taking proper action when a competing industry with better technology entered the picture. Since 2008, DVD rentals/sales have seen a sharp reduction [<a href="https://www.cnbc.com/2019/11/08/the-death-of-the-dvd-why-sales-dropped-more-than-86percent-in-13-years.html">link</a>]. Customers who were once eager to go to a store to get a DVD collectively decided to rent digital copies of films through newer services like Netflix and Hulu (there are more players in the market now). Blockbuster didn’t react quickly to the competing market that they had abandoned the whole industry, by filing for bankruptcy with a debt of $1 million in 2010. Of course, there are other examples like the vinyl industry where the company GZ media chose to be bold and win the abandoned market. From 2014 to 2015 their sales grew 40% by selling $25 million records. This shows that abandonment is not the only viable option during an industry’s decline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*__IbWsJuOcjSOQCg.png" /><figcaption>Blockbuster vs Netflix: [<a href="https://www.trioventsoftech.com/wp-content/uploads/2019/11/Redes_Sociales.png">Link</a>]</figcaption></figure><p>Sorry to have to end this on a gloomy note showing this image of Netflix pulling a Jaws on Blockbuster 😅. But remember that it is of utmost importance to have a deep knowledge of these stages an industry would live through, as future managers and/or entrepreneurs who would manage their own one day. We shall meet again on another business blog 👋🏽.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=335a7aa44e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embark to Understand — Strategy of a Company]]></title>
            <link>https://medium.com/@munsifmusthafa03/embark-to-understand-strategy-of-a-company-d6f2dbbd78a6?source=rss-7a60efe554cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6f2dbbd78a6</guid>
            <category><![CDATA[business]]></category>
            <category><![CDATA[goals]]></category>
            <category><![CDATA[vision]]></category>
            <category><![CDATA[corporate-strategy]]></category>
            <category><![CDATA[strategy]]></category>
            <dc:creator><![CDATA[Munsif Musthafa]]></dc:creator>
            <pubDate>Tue, 26 Oct 2021 13:03:45 GMT</pubDate>
            <atom:updated>2021-10-26T13:11:22.090Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embark to Understand — Strategy of a Company</h3><p>As a software engineer who works for a corporate organization, it has always piqued my curiosity to know how companies that are really large at scale operate. I will be going through some commonly studied business concepts in a series of blogs. The general knowledge of these are gained from a specially curated course by <a href="https://www.linkedin.com/in/valentina-bogdanova-emba-720a7758">Valentina Bogdanova</a> which has immensely helped me understand how the world outside of my closed box operates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*oIxZPXBlml88VWCF.jpg" /><figcaption>[<a href="https://globalfintechseries.com/wp-content/uploads/2021/09/Victory-Capital-Launches-Alternative-Investments-Platform-with-Acquisition-of-New-Energy-Capital-Partners.jpg">https://globalfintechseries.com/wp-content/uploads/2021/09/Victory-Capital-Launches-Alternative-Investments-Platform-with-Acquisition-of-New-Energy-Capital-Partners.jpg</a>]</figcaption></figure><p>A strategy is the means by which a company achieves its goals under conditions of uncertainty. This word was originally used in the military to which was recently adapted in the business world.</p><p>Strategy used to be well calculated in the earlier days but today, it’s a lot less predictable and requires analytical reasoning strategic position in the market.</p><h4>Successful companies in all ages and days have 4 things in common:</h4><ol><li>Simple, consistent and long-term goals</li><li>Deep analysis of the competitive environment</li><li>Objectively and effectively exploit company resources</li><li>Strong-willed leaders with solid decision making</li></ol><blockquote>Strategy is about making choices, trade-offs; it’s about deliberately choosing to be different. <br>- Michael Porter</blockquote><h3>The subtle distinction between Strategies</h3><p>Strategy is of two broad paths,</p><ul><li>Corporate strategy which ideates where the company wants to compete</li><li>Business strategy AKA Competitive strategy which ideates how a company needs to compete</li></ul><p>Let’s take a small look at the differences between each of these strategies and see how they support in a company’s growth.</p><h4>Corporate strategy</h4><p>A company’s top management will entirely decide on this to purview the scope of the entire company. It contains but not limited to Vertical integration, Diversification, Merges &amp; acquisitions, Capital intensive investments, Allocation of resources</p><ul><li>Which <strong>industry</strong> or industries should the company compete in</li><li>What should be the <strong>geographical scope</strong> of operations</li><li>Should the company <strong>diversify </strong>on business and to what level</li><li>How should a company be <strong>organized </strong>and type of vertical integration within the company. When to use in-house and out-sourced resources</li><li>Should the company enter <strong>alliances and/or acquisitions</strong></li></ul><h4>Business Strategy</h4><p>The decisions over here are headed by the business unit managers and divisional leads to gain a competitive edge.</p><ul><li>What sort of resources and capabilities should the company develop to gain a <strong>competitive advantage</strong></li><li>What is an efficient way to <strong>manage different business units</strong> to achieve <strong>strategic synergy</strong></li><li>How should the company <strong>monitor the industry environment</strong> to conform to market needs</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*JAHt1-PedPIx_eZU.png" /><figcaption>[<a href="https://cdn.icon-icons.com/icons2/2699/PNG/512/amazon_logo_icon_169612.png">https://cdn.icon-icons.com/icons2/2699/PNG/512/amazon_logo_icon_169612.png</a>]</figcaption></figure><p>As an example, <strong><em>Amazon </em></strong>as a company has their own Corporate and Business strategies which can be summarized as,</p><ul><li>Corporate: Largest online seller selling almost anything that can be sold, and continuously expanding their business into various geographies.</li><li>Business: Cost-leadership technique with the lowest cost of operation in the industry to increase profit, while having a strong emphasis on technology as an added booster.</li></ul><h3>Importance of Mission, Vision, Goals and Value Statements</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*IgLK-U-IaNncOhdy.png" /><figcaption>[<a href="http://www.bamksa.com/wp-content/uploads/2018/02/vision-mission-values.png">http://www.bamksa.com/wp-content/uploads/2018/02/vision-mission-values.png</a>]</figcaption></figure><p>An excellent way to validate a company’s purposes and goals is to formulate vision and mission statements, and supporting value statements to keep the company in check.</p><h4>Mission</h4><ul><li>What is the fundamental reason for an organization to exist</li></ul><h4>Vision</h4><ul><li>What does the organization want to achieve in the future</li></ul><p>There needs to be a set of <strong>Goals to achieve the vision</strong> expressed as a percentage, and a set of <strong>Objectives to achieve the Goals</strong>. Goals are usually targeted at different areas of a business like profitability, efficiency, retention and growth.</p><p>For example, the company would come up with a goal to <em>“to increase their revenue by 12% and decrease overheads by 6% in 2022”</em>. To achieve this, a couple of objectives would be to <em>“obtain 2 new customers per month” and “lease a low-cost space for the office premises”</em>.</p><p>While trying to achieve goals, there is a chance of overdoing something in the name of maximizing profits, that could be unethical. This is why most organizations stay behind a set of principles AKA <strong>Value statements</strong> which defines the values and places constraints on how the organization will achieve its goals. Many recruits not only look at large remuneration packages but also wants to join a company that is socially-responsible and upholds ethics, integrity and diversity.</p><p>It is very important how you choose your statements of vision and mission. When it comes to vision statements, some follow a very focused statement while some may go for a statement that reflects their business strategy, and unfortunately some companies go for vague statements. Let’s take a jab at how some well-known companies have written down theirs,</p><ul><li>Clear and focused — Prezi: To reinvent how people share knowledge, tell stories, and inspire their audiences to act.</li><li>State the business strategy — Warby Parker: To offer designer eyewear at a revolutionary price while leading the way for socially conscious businesses</li><li>Vague — Zappos: Delivering happiness to customers, employees, and vendors</li></ul><p>Similar to the vision, mission statements are also crucial in exhibiting the organization to the general public. Mission statements should be very clear, concise and motivating. Let’s see a couple of examples,</p><ul><li>Google — to organize the world’s information and make it universally accessible and useful</li><li>LinkedIn — connect the world’s professionals to make them more productive and successful.</li><li>Disney — to entertain, inform and inspire people around the globe through the power of unparalleled storytelling, reflecting the iconic brands, creative minds and innovative technologies that make ours the world’s premier entertainment company. (<strong>This is too verbose and difficult to remember</strong>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/0*nPYTmiaOVWJ2pVeV.png" /><figcaption>[<a href="https://www.logolynx.com/images/logolynx/fc/fcb9e5ec79f66560128bd0a490b1e71b.png">https://www.logolynx.com/images/logolynx/fc/fcb9e5ec79f66560128bd0a490b1e71b.png</a>]</figcaption></figure><p>A good set of value statements are written as a guiding principal to the employees and liaises what the company stands behind. Below are Sysco’s values,</p><ul><li>Rooted in Integrity</li><li>Committed to Inclusion</li><li>Drive Together</li><li>Define Excellence</li><li>Grow Responsibly</li></ul><p>It is a very interesting avenue to look at how each company sees itself in its own eyes and how it exhibits itself to the public, how it conducts itself and what it tries to achieve.</p><p>As I progress learning more on this, so shall you. We shall meet soon with more business related content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6f2dbbd78a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Containers in the Cloud]]></title>
            <link>https://medium.com/better-programming/containers-in-the-cloud-2fa2910d3d4a?source=rss-7a60efe554cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fa2910d3d4a</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Munsif Musthafa]]></dc:creator>
            <pubDate>Sat, 31 Aug 2019 17:24:28 GMT</pubDate>
            <atom:updated>2019-09-03T23:56:32.451Z</atom:updated>
            <content:encoded><![CDATA[<h4>The concept of containerization, when to use containers, and one of the most popular container services</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j0f3flZPBa9x2IHTYP5iRg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@teo?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Teo Zac</a> on <a href="https://unsplash.com/search/photos/container-cloud?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>TL;DR: Docker containers wrap up software and its dependencies into a standardized unit for software development that includes everything it needs to run.</p><p>Container orchestration using a cloud platform enables the running and the maintenance of enterprise-level containerized applications.</p><p>This week, I was going on a trip and my mother wanted to take a few of her medicines and took out a container, placing only the pills needed for the vacation.</p><p>Portable and easy, yes? As a technophile, I was quickly able to string in the connection between this and an interesting piece of maturing technology of the same name, <em>containers</em>.</p><p>This blog is to give a brief of the concept of containerization, when to use containers, and one of the most popular container services in the market right now for solo developers and enterprises.</p><p>Imagine these software containers to be similar to their real-world counterpart, they are portable and used to transport or move about material as a single unit.</p><h3>Container, Summarized</h3><p>I am pretty sure that, as software developers of the old, you have faced problems like needing to install a virtual machine for certain types of programs and dependencies to run.</p><p>You need different types of versions of transitive dependencies to be installed before running your application on other machines, moving applications through the software development lifecycle (SDCL) pipe into production, and the age-old problem of <em>it worked on my computer, though</em>.</p><p>Containerization is an old concept in the computing world which gained the spotlight in the recent past, when <a href="https://www.docker.com/get-started">Docker</a> introduced simplified tooling to create and manage containers. (Also, to note is that there are several new players in the market but this blog mainly relates to Docker).</p><p>The core idea of containerization evolved from <a href="https://opensource.com/resources/virtualization">virtualization</a> and acts like a companion. It dictates the idea of packaging or encapsulating software code with all of its dependencies so that it is able to run smoothly, consistently, and independently on any infrastructure.</p><p>This has evolved over the past half a decade and has proven its place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*FoN6P836pLX-ACcMXCqOgA.png" /><figcaption>[Source: <a href="https://www.docker.com/sites/default/files/d8/styles/large/public/2018-11/container-what-is-container.png?itok=vle7kjDj">https://www.docker.com/sites/default/files/d8/styles/large/public/2018-11/container-what-is-container.png</a>]</figcaption></figure><p>Some notable advantages of containerization could be summed up as:</p><ul><li>Removing the dependency of the host system from the application code.</li><li>Building easily scalable programs.</li><li>Simplified dependency management and versioning.</li><li>Being lightweight and flexible.</li><li>Isolated execution.</li><li>Predictability.</li></ul><p>But, as an individual developer or as someone who builds small scale applications, you would not be able to see or experience the vast array of benefits brought in by Docker and containers.</p><p>That’s where <a href="https://blog.newrelic.com/engineering/container-orchestration-explained/"><em>container orchestration</em></a> comes into play. Container orchestration is all about managing the lifecycle of containers, mainly in large and dynamic environments — an enterprise system.</p><p>Let’s take a turn and imagine that we are in fact working on an enterprise application which will be used by thousands of people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6W5hpi9r2Mr_C4j7KTfetA.png" /><figcaption>[Source: <a href="https://avinetworks.com/wp-content/uploads/2018/12/container-orchestration-diagram-1.png">https://avinetworks.com/wp-content/uploads/2018/12/container-orchestration-diagram-1.png</a>]</figcaption></figure><p>Amazon Web Services offers its own implementation of a container orchestration service, which we shall be looking into next.</p><h3>AWS Elastic Container Service</h3><p>For enterprise-grade applications or systems, it is de facto to go for Cloud-based deployment where you pay-as-you-go.</p><p><a href="https://aws.amazon.com/">AWS</a>, being the industry-leading XaaS provider, understood the impact containers make in building software and provides their own service, called the AWS <a href="https://aws.amazon.com/ecs/">Elastic Container Service</a> (ECS).</p><p>AWS ECS is designed to be a highly-scalable, high-performant container orchestration service that supports Docker containers. This service enables us to easily run and scale containerized applications in the Cloud.</p><p>Imagine a scenario where your application is a Java micro-service, expected to run on a Linux server, having its own micro-database, and you decide to build this on AWS.</p><p>In this case, deploying your micro-service using ECS and using <a href="https://aws.amazon.com/rds/">Relational Database Service</a> (RDS) by default provides you with the added benefit of fault-tolerance as well, which means we don’t have to worry about that when designing.</p><p>Also, the specific host a container runs on and its maintenance are all managed by the platform itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDnpCqkVPNcndz5INMIpjg.png" /><figcaption>[Source: <a href="https://d1.awsstatic.com/diagrams/product-page-diagrams/product-page-diagram_ECS_1.86ebd8c223ec8b55aa1903c423fbe4e672f3daf7.png">https://d1.awsstatic.com/diagrams/product-page-diagrams/product-page-diagram_ECS_1.86ebd8c223ec8b55aa1903c423fbe4e672f3daf7.png</a>]</figcaption></figure><p>AWS provides new terms for its services and modules. Let’s learn them along the way. For this, let’s take a small scenario similar to the above.</p><p>Imagine we need to run an application server (app_1) which also requires a small cache service (app_2) to run alongside it.</p><h4>Task definition</h4><p>As the name sounds, it’s the <em>blueprint</em> for a task. Think of a Java Class. It dictates which containers are to be run.</p><p>In the above example, it would declare both the applications to run in two containers in a single task. It also defines the details, such as environmental variables, to be used, CPU and memory allocations, exposed ports, and how each of the containers would interact.</p><p>The number of tasks to be run is also declared in this.</p><h4>Task</h4><p>A task is an <em>instance</em> of the above blueprint. Think of an Object of a Java Class. Tasks are run as configured via its task definition, allowing multiple tasks to be run from a single definition.</p><p>In our example, one task would run both the app_1 container and the app_2 container.</p><h4>Service</h4><p>Service allows you to run and maintain the specified number of instances in a task definition, simultaneously in a cluster.</p><p>This sustains the minimum and maximum tasks at a given time and manages more things, including load balancing and auto-scaling of the containers.</p><p>For example, in our case, due to high load at a specific time, if the CPU starts to throttle, the service checks for the maximum number of allowed tasks to run and increases the number of tasks one-by-one until a given average threshold is achieved.</p><h4>Container instance</h4><p>These tasks (and containers) need to be run somewhere to be accessed — enter container instances. Container instances are EC2 instances that run Docker and a special piece of software called the <em>ECS Agent</em><strong> </strong>and registered into the Cluster of instances.</p><p>Each of these instances has the ability to run one or more tasks (i.e. one or more containers), given that it has physical resources available. Also, to note is that a container instance can run tasks from one or more Services.</p><p>The Agent acts as the bridge between these instances and ECS by providing the statuses of the running containers and managing spawning new containers in an instance.</p><h4>Cluster</h4><p>A Cluster is a group of <em>ECS container instances</em>. The ECS facades all the complications of maintaining, scheduling, and scaling these instances.</p><p>Also, based on the <em>placement strategy</em>, it places new container spawns in optimal instances and abstracts the pain away.</p><p>When you have multiple software modules that run independently as parts of your product, you can place several of them in one cluster, which enables optimal usage of resources and actually minimizes the setup time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6YbUmNJjzfnX71GHw6_1_g.jpeg" /><figcaption>AWS ECS summarized</figcaption></figure><h3>Conclusion</h3><p>We have seen how immensely containerization helps the software development process, by addressing multiple pain-points and manual labor of a software developer.</p><p>Similarly, how the AWS Cloud platform addresses multiple challenges of a DevOps engineer.</p><p>We have a basic understanding of the container orchestration service AWS provides to ease the process of managing an enterprise-level containerized application in the Cloud.</p><p>I’ll try some practical applications on this and catch up with more on working with enterprise-level containerized applications and memory management in upcoming blogs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fa2910d3d4a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/containers-in-the-cloud-2fa2910d3d4a">Containers in the Cloud</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a File Upload Service to your Google Drive using OAuth 2.0]]></title>
            <link>https://medium.com/@munsifmusthafa03/building-a-file-upload-service-to-your-google-drive-using-oauth-2-0-d883d6d67fe8?source=rss-7a60efe554cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/d883d6d67fe8</guid>
            <category><![CDATA[oauth]]></category>
            <category><![CDATA[file-upload]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[google-drive]]></category>
            <dc:creator><![CDATA[Munsif Musthafa]]></dc:creator>
            <pubDate>Tue, 16 Oct 2018 05:57:12 GMT</pubDate>
            <atom:updated>2018-10-16T05:57:12.471Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This blog post will steer you through the technicalities of OAuth 2.0 and how to make use of the resource sharing capabilities.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*D57AWE-MKMCswQXW" /></figure><p>Now this is one of those buzzwords that gets thrown around quite frequently, but majority of the internet users have no clue of this whatsoever. Before we look at what this OAuth is, first I’d like to start with the difference between authorization and authentication.</p><p>Simply put, <strong>Authentication </strong>is <strong>who you are</strong> and <strong>Authorization </strong>is <strong>what you are allowed to do</strong>. When elaborated, authentication verifies the user and decides if he/she is part of the system whereas, authorization is when the system knows you but needs to verify whether you are allowed to access a certain resource or not.</p><h3>What is OAuth 2.0</h3><p>OAuth or Open Authorization is a framework for delegated authorization. The <a href="https://tools.ietf.org/html/rfc6749">specification </a>mentions on how unrelated servers and services can safely allow authenticated access to their resources without actually sharing the any initial credentials. OAuth came into play to provide the online web application users (not only web application as time went by) with a seamless user experience. You use hundreds of websites daily, and are required to register yourself into at least half of them. It is not humanly possible to remember hundreds of different login credentials. This is one place where OAuth helps remove that pain point from your online experience.</p><p>Let’s look at this example below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*aHtSHiFlmBpdh5GBBS2oGw.png" /><figcaption>Life before OAuth</figcaption></figure><p>Imagine that a new viral social media site has emerged and you decide to signup for your fair share of fun. But sadly, once you logged in, you can’t seem to find any of your friends in that site. But the site tells you that if you let it access your contacts list from another mail provider, it will check and let you know if any of your friends are in this site and if not, send an email on behalf of you to ask them to join here. But the catch is that you have to type in your email address and password of the mail provider in this website, so that the social media site can log in on behalf of you to the mail provider and access your contact list there for further processing. <em>How safe is this? Can you trust a 3rd party application with your personal credentials of another service provider?</em></p><p>Enter OAuth. OAuth has defined flows that allows for safe and secure resource sharing by delegating authorization with the users’ consent. OAuth 2.0 now provides authorization flows for web and desktop applications, and mobile devices. Let’s start with OAuth roles.</p><h4>OAuth Roles</h4><p>OAuth 2.0 defines four roles:</p><ul><li><strong>Resource Owner</strong>, is the user who authorizes an application to access their account. The client application’s access to the user’s account is limited to the “scope” of the authorization granted.</li><li><strong>Client</strong>, is the <em>application </em>that wants to access the user’s account but it must be authorized by the user first then verified by the authorization server.</li><li><strong>Authorization Server</strong>, verifies the identity of the user and issues access tokens to the client application.</li><li><strong>Resource Server</strong>, contains the protected user accounts’ resources.</li></ul><h4>Abstract Flow of the Protocol</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*9_joiKyNQiNvqGGrqQkQPQ.png" /><figcaption>Abstract Flow of the OAuth 2.0 Protocol</figcaption></figure><ol><li>The application requests authorization to access some protected resources in the server where user is already authenticated and authorized.</li><li>If the user authorized the request, the application receives an authorization grant after consent.</li><li>The application requests an access token from the authorization server by presenting authentication of its own identity, and the authorization grant it received after user consent.</li><li>If the client application’s identity is authenticated and the authorization grant is valid, the authorization server issues an access token to the application, completing the authorization.</li><li>The client application requests the resource from the resource server by presenting the access token for authentication</li><li>If the access token is valid, the resource server serves the resource to the client application</li></ol><p>But the actual flow is dependant on which authorization grant type is used. A grant is a method of acquiring an access token. Let’s now look at what the 4 most used grant types are and let’s how we can implement a client application of our own.</p><h4>Authorization Grant Types</h4><ul><li><strong>Authorization Code Grant</strong>, is most commonly used for server-side applications. This is a redirection-based flow, meaning the application must be capable of interacting with the client browser to handle re-routes.</li><li><strong>Implicit Grant</strong>, is used for single page web applications and mobile applications, where the client secret confidentiality is not guaranteed. This flow does not authenticate the identity of the application, and relies on the redirect URI provided while registering.</li><li><strong>Resource Owner Password Credentials Grant</strong>, is where the user provides their username and password credentials directly to the client application. This should only be used if the application is trusted by the user (generally a mobile version of the same vendor of the web app).</li><li><strong>Client Credentials Grant</strong>, provides an application a way to access its own resources and is used by client applications to obtain an access token outside of the context of a user.</li></ul><p>Which one these grants to use is clearly described in the below flowchart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rnCOltgEiL9FiWj58ag1rA.png" /><figcaption><a href="https://oauth2.thephpleague.com/images/grants.svg">https://oauth2.thephpleague.com/images/grants.svg</a></figcaption></figure><p>Next up we shall take a look at how to leverage one of these flows to build your very own OAuth-based client application.</p><h3>Step I: Application Registration</h3><p>First you must register your application with the service provider. This is done through a registration form in the “developer” portal of the service’s website (<a href="https://console.developers.google.com/">Google in our case</a>), where you will provide the,</p><ul><li><em>Application Name</em></li><li><em>Application Website</em></li><li><em>Redirect URI </em>or <em>Callback URL</em></li></ul><p>Redirect URI is where the Google will redirect the user after he/she authorizes our application and is the part of the application that will handle authorization codes and/or access tokens. Once you have successfully registered your application, Google will provide your application with some credentials which include,</p><ul><li><em>Client Id</em> — this is publicly exposed for Google to identify your app</li><li><em>Client Secret</em> — this is used to authenticate your app to Google (private)</li></ul><p>Below are few snips of the steps of generating the client credentials for your application/ website by registering the application name and callback URI.</p><h4>1. Create a project in the Google developer console</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bf23MBzskr5jeUjmp7qDBA.png" /><figcaption>1. Create a project in the Google developer console</figcaption></figure><h4>2. Enable the Google Drive API to generate your client credentials</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*49c4LiH2kcY_7w9BFdQxeg.png" /><figcaption>2. Enable the Google Drive API to generate your client credentials</figcaption></figure><h4>3. Click on Create Credentials button to start the progress</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tj69pUwPIUUwaFcgMO0LpQ.png" /><figcaption>3. You will have to click on Create Credentials button to start the progress</figcaption></figure><h4>4. Fill out the details of the client application</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JPP8bxOvk1arKq24f9rDIw.png" /><figcaption>4. Fill out the forms where you are required to give the aforementioned attributes of the client website/application</figcaption></figure><h4>5. Once completed, your client credentials will be generated</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFXIBTFdwYXW4h_s6eG35g.png" /><figcaption>5. Once you have completed all the steps your client credentials will be created and registered in Google</figcaption></figure><h3>Step II: Building the Client Application</h3><p>The application we are building today will be using Authorization Code Grant Type to demonstrate the OAuth capabilities. The application is built using Spring Boot and the Google Client Library for OAuth and Drive, which makes things relatively easier (if you understand the API that is…)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4CJFKe7aIstJuxgHoEHV6Q.png" /><figcaption>Login page with Google SSO enabled</figcaption></figure><p>The user will need to be redirected to the <em>consent page</em> to give permissions for the application to make use of the user’s drive account. This is the request the Authorization Endpoint of Google expects from the client application,</p><p><a href="https://accounts.google.com/o/oauth2/auth?access_type=offline&amp;client_id=XXXXXXXXX.apps.googleusercontent.com&amp;redirect_uri=http://localhost:8080/oauth/callback&amp;response_type=code&amp;scope=https://www.googleapis.com/auth/drive">https://accounts.google.com/o/oauth2/auth?access_type=offline&amp; client_id=XXXXXXXXX.apps.googleusercontent.com&amp;redirect_uri=http://localhost:8080/oauth/callback&amp;response_type=code&amp;scope=https://www.googleapis.com/auth/drive</a></p><p>The component query params of the url are as follow,</p><p>access_type — Indicates whether your application can refresh access tokens when the user is not present at the browser. Valid parameter values are online, which is the default value, and offline.</p><p>client_id — The client ID for your application</p><p>redirect_uri — Determines where the API server redirects the user after the user completes the authorization flow.</p><p>response_type — Expected response from the server. For <em>Authorization Code</em>, the value is <em>code</em></p><p>scope — A space-delimited list of scopes that identify the resources that your application could access on the user’s behalf</p><p>When run, you are presented with the screen as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2rGW0KdT0ntVKgETINqRag.png" /><figcaption>Selecting your user account and log in to it</figcaption></figure><p>The implementation of the above is shown in the below service and controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f193c077cb8eed5e8af8b848cd96758/href">https://medium.com/media/7f193c077cb8eed5e8af8b848cd96758/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f637ddb507e20273d8ea7523d5211bae/href">https://medium.com/media/f637ddb507e20273d8ea7523d5211bae/href</a></iframe><p>When the user is redirected to the Authorization Endpoint, Google will prompt the user with the below <strong>consent page</strong> where the user would allow or cancel the permission request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHn1bO8d9aM4DmW5SmsqHw.png" /><figcaption>Giving the <strong>View and manage the files in your Google Drive </strong>permissions to the client application</figcaption></figure><p>And redirected to the Homepage of your application based on the callback URI or the redirect URI you provided for your client application. The implementation for handling the callback is given in the above controller and service classes under the <em>GetMapping for “/oauth/callback”.</em></p><p>Each request to upload a file to the Drive from the user’s browser is sent with an Authorization Header like Authorization: Bearer XXXXX where XXXXX is the <em>Access Token </em>the application has received from Google by exchanging the <em>Grant Code.</em> P.S. This happens internally when you use the Google client SDK like I did for this example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iVunNSVz4m_W3rbH6Qfmxg.png" /><figcaption>You are redirected to the homepage after signing into Google Drive</figcaption></figure><p>Now you are free to upload any type of file to your Google drive with this very minimalistic application. You can find the complete implementation of this application in <a href="https://github.com/munsif3/oauth-2.0-app">my GitHub repository</a>.</p><p>For more information on building applications, leveraging the OAuth framework and the Google APIs, refer the following links.</p><ul><li><a href="https://tools.ietf.org/html/rfc6749">RFC 6749: The OAuth 2.0 Authorization Framework</a></li><li><a href="https://developers.google.com/products/">Google Developers</a></li><li><a href="https://developers.google.com/identity/protocols/OAuth2">Using OAuth 2.0 to Access Google APIs | Google Identity Platform</a></li><li><a href="https://developers.google.com/api-client-library/java/google-oauth-java-client/setup">Setup Instructions | OAuth Client Library for Java | Google Developers</a></li></ul><p>See you in the next post. Ciao.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d883d6d67fe8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSRF Protection Episode 2. Double Submit Cookie Pattern]]></title>
            <link>https://medium.com/@munsifmusthafa03/csrf-protection-episode-2-double-submit-cookie-pattern-195824e53d42?source=rss-7a60efe554cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/195824e53d42</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[double-submit-cookie]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[synchronizer-token]]></category>
            <category><![CDATA[csrf]]></category>
            <dc:creator><![CDATA[Munsif Musthafa]]></dc:creator>
            <pubDate>Mon, 08 Oct 2018 06:59:22 GMT</pubDate>
            <atom:updated>2018-10-08T14:02:19.450Z</atom:updated>
            <content:encoded><![CDATA[<p>In my previous blog post, I had discussed about the Synchronizer Token Pattern (STP) and how it is implemented. This post is about the second most common way to use the Anti-CSRF Token, the Double Submit Cookie pattern.</p><h3>Introduction</h3><p>Double Submit Cookie Pattern (DSCP) comes into play when you have limited server resources and you cannot afford to keep track of each and every token for each session (and a bigger hassle when one user can have multiple sessions).</p><h3>Flow of Events of Double Submit Cookie Pattern</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fxlNp1eJspsbP9s_SV-8oQ.png" /><figcaption>Flow of Events of Double Submit Cookie Pattern</figcaption></figure><p>The main difference here compared to the Synchronizer Token Pattern is that the generated <strong>Token is not stored in the server-side</strong> and server has no record of the token. All the server does is generate the token and send to the client-side. From there onward, the token will be only available in the client-side, which requires that <strong>you should not set this token cookie as <em>HttpOnly</em></strong> (as JavaScript on the browser needs to read this cookie).</p><p>When a user logs into the secure website, his/her credentials are verified and the user is authenticated. The server then creates a session id for the user and sets it as a cookie in the response. Similarly a <strong>token cookie is also generated and set as a cookie</strong>. The server needs to store the session id for the user (to keep track of the user), but does not store the token for that session.</p><p>As soon as the authentication response gets sent to the client browser, the client-side script (JavaScript in this case) r<strong>eads the token cookie, extracts the value and embeds it in the state-changing operation form as a hidden field</strong>. Once the user fills in the fields and submits the form, the request gets sent with the token cookie (and the session cookie) in the header and also the same token value in the request body.</p><p>Now when the request is received by the server, the value in the <strong>token cookie and the token value in the request body</strong> are extracted and compared to see <strong>if they match</strong>. If yes, the requested state-changing action gets executed.</p><h3>Sample Implementation</h3><p>The same example Spring Boot application used in <a href="https://medium.com/@munsifmusthafa03/csrf-protection-episode-1-synchronizer-token-pattern-f133cb5eb7fe">the previous blog post about Synchronizer Token Pattern</a> as before, with minor changes to the server-side code will be used as the demo here as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MXVmZSrBtUeTZw5mo50r3A.png" /><figcaption>Login page</figcaption></figure><p>When the user logs in, his credentials will be validated and allowed in to the home page. The code below is the MainController which handles the authentication, and adds the session cookie and the token cookie to the response. Also in the below code is the PostMapping for <strong>/blog</strong>, which in this case would be the state-changing operation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42a156f0a6603b99daf3574ee51f2c4d/href">https://medium.com/media/42a156f0a6603b99daf3574ee51f2c4d/href</a></iframe><p>The <strong>session id </strong>and the <strong>csrf token </strong>cookies can be seen in the client browser as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*LV4CwY16d9IODp2nMqdIDA.png" /><figcaption>Cookies stored in the browser cookie storage</figcaption></figure><p>The service class implements the authentication and validation mechanisms as shown in the gist below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a681a00f9a23555db3cb01502c7cef32/href">https://medium.com/media/a681a00f9a23555db3cb01502c7cef32/href</a></iframe><p>If and only if the request that’s being send includes the token in both the header and the body, the request will be authorized to flow through the server.</p><h4>How secure is this?</h4><p>A cross-origin attacker will not be able to read any information from the server nor modify the cookie values, as per the same-origin policy. But still an attacker can trick the authenticated user to send a malicious request to the valid url, but without the token cookie value in the attacker’s request body, the request would be immediately failed by the server. Therefore, as long you do not explicitly enable cross-origin requests to the server, your application is safe.</p><h4>Or is it really?</h4><p>But recently security researchers from <a href="https://www.owasp.org/images/3/32/David_Johansson-Double_Defeat_of_Double-Submit_Cookie.pdf">OWASP have released a possible attack that could bypass the Double Submit Cookie pattern</a> and orchestrate a CSRF attack. The server having no knowledge of the token cookie is one of the causes for the aforementioned problem. There are found possibilities for an attacker to set the cookies by Exploiting subdomains and Man-in-the-middle alterations in plain HTTP connections.</p><p>Await more interesting posts…</p><p>If you enjoyed this article, please hold down the clap button below 👏 to help others find it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=195824e53d42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSRF Protection Episode 1. Synchronizer Token Pattern]]></title>
            <link>https://medium.com/@munsifmusthafa03/csrf-protection-episode-1-synchronizer-token-pattern-f133cb5eb7fe?source=rss-7a60efe554cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f133cb5eb7fe</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[cookies]]></category>
            <dc:creator><![CDATA[Munsif Musthafa]]></dc:creator>
            <pubDate>Sun, 07 Oct 2018 12:30:07 GMT</pubDate>
            <atom:updated>2018-10-08T14:02:04.822Z</atom:updated>
            <content:encoded><![CDATA[<p>In my previous blog post, I had discussed about Cross-site Request Forgery, how it happens. I had mentioned about a couple of preventative measures that web application developers could follow to provide a safe and better experience to their users.</p><h3>Introduction</h3><p>The basic flow of events in a normal “secure” client-server request-response would go as follows. Client types in his/her credentials and clicks Sign In, which sends a POST request to the server. The server would check if the username and password matches with what’s there in its storage. If the user is a match, server would generate a session cookie, store it against the username and send it back in the response header as <em>set-cookie=abc123.</em> The client browser would then store this session cookie in the cookie storage and send it along any subsequent requests made to the server. The issue with this is any malicious party could trick the authenticated user externally to send in a request on behalf of the attacker unbeknownst to the user. In this post, we shall take a look at the <strong>Synchronizer Token Pattern</strong> and a quick example application which implements this pattern.</p><h3>Flow of Events of Synchronizer Token Pattern</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*iBAaPi-CIiigbfVn5rLAhQ.png" /><figcaption>Flow of Events of Synchronizer Token Pattern</figcaption></figure><h4>Flow of events</h4><p>The difference here is that alongside generating and sending a session cookie, the server would also generate a token and store it against the sessionId for the user. Then the web page with the state changing operation, would make an AJAX call internally to the token end-point of the server to retrieve the token from the server. The JavaScript that runs on the page would then extract the token from the response and embed it into a hidden field inside the form. When the user clicks on the button to submit the page, the request that goes would contain the session cookie in the header, and the token as a field in the body. The server can now verify and validate the request and make sure no forging has been done.</p><h4>Why is this secure?</h4><p>Of course still a malicious entity could do some social engineering and manipulate the the user into clicking or executing a state-changing operation from the client browser unbeknownst to the user. The attacker could easily forge a similar form with all hidden fields and execute the url from the user’s browser… and that server’s relevant session cookie would be sent along the request too. But the request would fail on the server side. The reason is that the the token embedding cannot be carried out by the attacker because cross-domain AJAX calls are blocked by default.</p><h3>Example Implementation</h3><p>This sample application is implemented using Spring Boot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MXVmZSrBtUeTZw5mo50r3A.png" /><figcaption>Login page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6KDFdaSJ7YK1ZDgsPk0T2A.png" /><figcaption>Homepage with the state changing operation</figcaption></figure><p>Below is the login page, which uses Thymeleaf for as the templating engine.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18ab7c748828aecd81769d156b3a747c/href">https://medium.com/media/18ab7c748828aecd81769d156b3a747c/href</a></iframe><p>The login action submits the credentials to the server. I don’t want to go deep on how Thymeleaf handles the data binding (it’s a topic for another time).</p><p>Next up we shall take a look at the Main Controller which for simplicity’s sake would handle our Login post request and the subsequent state changing post request to add a blog post.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1057fbf2f8e2f87aabf44925173b51b/href">https://medium.com/media/f1057fbf2f8e2f87aabf44925173b51b/href</a></iframe><p>Next up we’ll look at the Service class which processes the requests, i.e. validate user, validate session, validate token and so on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82d5b5bee588469c3e1fd01a436b10f6/href">https://medium.com/media/82d5b5bee588469c3e1fd01a436b10f6/href</a></iframe><p>Next up is the redirected add blog/home page, which contains the state-changing <strong>POST </strong>operation (create) and the associated JavaScript which sends a <strong>GET </strong>request to the <strong>token end-point</strong> and <strong>embeds the token into a hidden field</strong> in the form body.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8098d3c543f78cdcf44cebc7960ed89/href">https://medium.com/media/c8098d3c543f78cdcf44cebc7960ed89/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f48453b5fd00ab86da76da052e9b131/href">https://medium.com/media/4f48453b5fd00ab86da76da052e9b131/href</a></iframe><p>Once the user submits the form, it gets sent to the post end-point and in the request body is the form fields which contains the hidden field witht the token value. How the <em>“synchronizer”</em> validation is done in the server is also available in the gist above “MainController.java”. Upon receiving the request the server will validate the token from the body.</p><p>The full implementation of this pattern can be found in this <a href="https://github.com/munsif3/csrf-protection-synchronizer-token">GitHub link</a>.</p><p>In the next blog, we shall look at how the Double Submit Cookie pattern works and its implications.</p><p>If you enjoyed this article, please hold down the clap button below 👏 to help others find it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f133cb5eb7fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How users are tricked into Cross-site Request Forgery]]></title>
            <link>https://medium.com/@munsifmusthafa03/how-users-are-tricked-into-cross-site-request-forgery-3c48b87b5ae6?source=rss-7a60efe554cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c48b87b5ae6</guid>
            <category><![CDATA[sessions]]></category>
            <category><![CDATA[cookies]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[request-forgery]]></category>
            <category><![CDATA[csrf]]></category>
            <dc:creator><![CDATA[Munsif Musthafa]]></dc:creator>
            <pubDate>Sun, 07 Oct 2018 08:26:40 GMT</pubDate>
            <atom:updated>2018-10-08T14:01:47.827Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWNKmF82FvzGSraTxzm6QQ.png" /><figcaption><a href="https://fourdots.com/wp-content/uploads/2016/08/its-a-trap4-1.png">https://fourdots.com/wp-content/uploads/2016/08/its-a-trap4-1.png</a></figcaption></figure><h3>Introduction</h3><p>Cross-site request forgery or <strong>CSRF</strong> is a type of attack on authorized users where a “man-in-the-middle” adversary would trick this authorized user into transmitting commands unknown to the user on behalf of the attacking entity, in a web-based application. This is also known as <strong>one-click attack</strong> and <strong>session riding</strong>. One-click attack because, it click-baits users into the attack by social engineering, and session riding because it takes an authorized session cookies along with the request. The magnitude of attack is solely based on the access level that particular authorized victim has. CSRF attack exploits the trust, the server has created with the current user’s client session.</p><h3>How CSRF Works?</h3><p>The idea of CSRF attacks is made possible by the open trust, server creates with a client browser. When you log into a website (<strong>good.example.com</strong>), the server generates a <strong>sessionID cookie </strong>(in most cases), stores it in server-side against the logged in username, and sends back to the browser, where it is stored in the browser’s cookie storage. Cookies are involved into play majorly because HTTP is stateless and the server need to remember the user and the user interactions to provide a good experience.</p><p>When you make web page requests or rest calls from that logged in website, the sessionID cookie is sent with each of the requests. The server then authorizes these requests by checking the availability of the received session cookie with in the server-side. If it is available, the request is authorized and does what it is intended to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*lue_IXcsuuqlBmlaSlAxEg.png" /></figure><p>When you open a malicious website (<strong>evil.example.com</strong>), the attacker has taken your authorized session on the <strong>good.example.com </strong>website “on-a-ride”. The attacking entity does two main things to accomplish this task,</p><ol><li>Trick the user into clicking or loading the malicious page</li><li>Send the forged request via the user’s authorized session</li></ol><p>The first task is accomplished using social engineering, which is something that works profoundly well in this time and age.</p><h4>Attack using POST request</h4><p>The user is tricked by showing something attractive and very click-baity. Obviously the general user would not know that the link he/she is about to click would trigger a request to the good.example.com on behalf of the attacker. The post request would send the form body along with the cookie associated with the website, to the server. The server would consider it a legitimate request but in reality, it is made by the an unaware user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*pAsY8wqUxqnt06d41e19jA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eTRqLcPRs9L3yFT9SNaHzA.png" /></figure><h4>Attack using GET request</h4><p>Something to note here is that the attacker may also have a other ways that could automatically trigger the malicious request on the page load event. The request <em>url </em>could be set as the <em>src </em>of an <em>img</em> tag that has height and width set to 0px. It could also be an AJAX request that automatically hits the url on page load. Similarly here, the request to load the “image” into view, the cookie associated with the website will be sent along the request, where the malicious actor has successfully used the server’s trust to his advantage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*XALG6kNGnc1C_kpvZY_N1Q.png" /></figure><p>These are not the only ways for someone to execute CSRF attacks. The attacker can also use an iframe, that would have its attributes set to invisible. Using the same onload function, the attacker can then load the iframe of their own malicious web application. As soon as the iframe loads, the request will be sent to the main website server and executed.</p><h3>Prevention</h3><p>CSRF attacks were in the 8th position in the <a href="https://www.owasp.org/images/7/72/OWASP_Top_10-2017_%28en%29.pdf.pdf">OWASP Top 10 2013</a> but thanks to security best practices and techniques followed by the web application developers, it has been taken down from the 2017 list. The most common implementation to prevent CSRF attacks is using <strong>Anti-CSRF Tokens,</strong> which is implemented in two common patterns namely,</p><ol><li>Synchronizer Token Pattern</li><li>Double Submit Cookie Pattern</li></ol><p>which I will be discussing further in my follow up posts. Other than the usage of CSRF tokens, Same Site Cookies can be used to completely mitigate this problem. Same Site flag in cookies allow cookies to be sent only if the request originates from the same origin as the domain of the cookie is. But this has not been adapted widely as of now. When it becomes the popular choice of CSRF prevention, we can have much better user experience online.</p><h3>Conclusion</h3><p>Browser cookies get sent automatically by the browser to the server with each request, because it’s the only way HTTP can keep track of the user (usually). This is also the gateway for malicious entities to craft attacks and execute on the server using the authorized user’s elevated rights. While CSRF does not target data retrieval, it can do a lot of damage by targetting state-changing operations on the server being attacked.</p><p>Keep an eye out for posts on Anti-CSRF Tokens.</p><p>If you enjoyed this article, please hold down the clap button below 👏 to help others find it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c48b87b5ae6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Threats to Information Security and What the Hash you could do about it?]]></title>
            <link>https://medium.com/@munsifmusthafa03/threats-to-information-security-and-what-the-hash-you-could-do-about-it-93bef04f7049?source=rss-7a60efe554cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/93bef04f7049</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[hash-collision]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[hashing]]></category>
            <dc:creator><![CDATA[Munsif Musthafa]]></dc:creator>
            <pubDate>Tue, 28 Aug 2018 07:51:18 GMT</pubDate>
            <atom:updated>2018-08-28T07:51:18.608Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*fGRS9VY51UunHrKJD88CKA.png" /><figcaption><a href="http://www.mfbzone.com/img/my%20pages/information.png"><em>http://www.mfbzone.com/img/my%20pages/information.png</em></a></figcaption></figure><h3>What are Hash Functions?</h3><p>A cryptographic hash functions is a mathematical formula that helps you convert a given value to another value that is of a fixed length and is irreversible. The result is much smaller than that of the original input to the function and are comparatively faster (unlike in using cipher techniques). A good hash function will never result give the same result for two distinct inputs; even if a bit is changed the whole hash value changes (avalanche effect). I mentioned that hash functions are faster compared to ciphers. But they shouldn’t be able to compute too quickly either, which may result in the function being labeled as brittle. These attributes of hash functions allows them to be used in multitude of real-world use cases like,</p><ul><li>Integrity protection in messages and software</li><li>Hashing the certificate in HTTPS</li><li>Digital signature</li><li>Creating database indexes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*C406LolgeI_f3wFR.png" /><figcaption><a href="https://cdn.auth0.com/blog/hashing-one-way-road-to-security/hash-flow.png">https://cdn.auth0.com/blog/hashing-one-way-road-to-security/hash-flow.png</a></figcaption></figure><h3>Types of Hash Functions</h3><p>There are several types of hash functions available for each of the scenarios mentioned above and some, designed with different concepts and goals in mind. There are 2 main families of hash functions Cryptographic and Non-cryptographic.</p><p>Cryptographic hash functions have several properties including but not limited to,</p><ol><li>Deterministic — same input outputs same digest</li><li>Quick — quick to calculate</li><li>One-way function — cannot “de-hash” and retrieve the input</li><li>Avalanche effect — even a small change results in complete change to the digest</li><li>Collision resistant — two different inputs cannot yield the same output</li><li>Pre-image attack resistant — should resist attack attacks in its pre-image</li></ol><p>Contrarily, non-cryptographic hash functions trades-off security features to an extend in exchange for improvements in performance. Non-cryptos try to only avoid collisions for “non-malicious” inputs.</p><h4>Cryptographic Hash Functions</h4><ol><li>Keyed</li></ol><ul><li>Requires the digest as well as a key for calculating the result</li><li>HMAC, One-key MAC, BLAKE2</li></ul><p>2. Unkeyed</p><ul><li>Requires to produce only the hashed value/digest</li><li>MD5, SHA256</li></ul><p>3. Checksum</p><ul><li>Detecting errors that might have been introduced in data exchange.</li><li>Sum, Mod-10</li></ul><p>4. Cyclic Redundancy Checks</p><ul><li>Error-detecting code used in identify changes to raw data. Similar to checksum.</li><li>CRC-16, CRC-32</li></ul><h4>Non-Cryptographic Hash Functions</h4><ul><li>Pearson, Java hashCode, MurmurHash</li></ul><h3>Breaking Hash</h3><p>As I’ve previously mentioned, a good cryptographic hash function should not yield the same output for two distinct inputs. If a hash function produces the same value for different inputs a.k.a “Hash Collision”, the function is not longer “secure” and will be demoted from being a cryptographic hash function to non-cryptographic hash function.</p><h4>Why does this happen?</h4><p>The reason is the pigeon-hole principle, which is a mathematical principle that states that when <em>n</em> number of items is put into <em>m</em> containers where <em>n &gt; m, </em>it is unavoidable that at least one container must contain more than one item. In the information security world, cryptographic hash functions can produce only a certain set of values based on the number of bits it can output, which might result in <strong>two inputs ending up with the same output</strong>. For example, SHA1 can produce only outputs of length 160 bits and MD5 with only 128 bits. These two hash functions are now considered “broken” because they are proven to produce the same output for distinct inputs in at least one case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*SL2xUaETv6MKM00B.png" /><figcaption><a href="https://steemitimages.com/DQmevFVotrr7YHgr6XCwPFy1h7NxE69VmtktMAhKRFSovD5/image.png">https://steemitimages.com/DQmevFVotrr7YHgr6XCwPFy1h7NxE69VmtktMAhKRFSovD5/image.png</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/0*EBJO2Mgyn54VFhiN.png" /><figcaption><a href="http://shattered.io/static/infographic-small.png">http://shattered.io/static/infographic-small.png</a></figcaption></figure><p><a href="http://shattered.io/">Shattered.io</a> has conducted experiments, broken SHA1. In their site, it is shown that two distinct PDF files (one with a blue background and the other with red) have produced the same sum. Even though this act has demoted it from being cryptographically secure, that does not mean all your implementations using SHA1 are broken. This simply means that it could very rarely be used to send something malicious but the probability is like a scenario where a 2 people in Colombo might have the same hair count. Nothing serious, but better to be cautious and switch to the SHA2 family (SHA256, SHA512). But the “broken functions” still maybe used in cases like file authenticity verification, or file transmissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*bab3QOH4Wr_DrfcV.png" /><figcaption><a href="http://shattered.io/static/shattered.png">http://shattered.io/static/shattered.png</a></figcaption></figure><h4>Ways of Breaking a Hash Function</h4><p>Cryptographers have come up with three different kinds of possible attacks on hash functions.</p><ol><li>Collision attack — finding two different inputs B1 and B2 where hash(B1) = hash(B2)</li><li>Pre-image attack — given a digest H, find any value V where H = hash(V)</li><li>Second pre-image attack — given one input B1, find any other value B2 where hash(B1) = hash(B2)</li></ol><p>To overcome your security concerns of someone breaking the hash functions you’re currently using, always opt-in for newer revised cryptographic hash functions that are resistant to the above mentioned three attacks; using newer hash functions like SHA3, BLAKE, Skein, and etc.</p><p>The aforementioned attacks can be seen as ways of cracking hash functions. But malicious entities in most cases would want to crack passwords where one could opt for using,</p><ul><li>Rainbow tables — using pre-computed tables for reversing the values of the input for a hash function by using more space for storing the table</li><li>Brute-force attacks — calculate hashes for all possible inputs in real-time by using more computational power</li></ul><p>which is a classic example of the space-time trade-off. The simplest precaution that can be taken overcome these attacks is to use “Salted Hashing”, which I have mentioned in my <a href="https://medium.com/@munsifmusthafa03/what-the-hash-a-simple-guide-to-hashing-9cdbacb4aa8c">previous post</a>. If the salt is long and random enough, your hashing is strong.</p><p><em>Originally published at </em><a href="https://munsifmusthafa.blogspot.com/2018/08/breaking-hash.html"><em>munsifmusthafa.blogspot.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93bef04f7049" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>