<?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 Randi Adhityas Saputra on Medium]]></title>
        <description><![CDATA[Stories by Randi Adhityas Saputra on Medium]]></description>
        <link>https://medium.com/@randiadhityassaputra?source=rss-902c700e3176------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NdNJnRR81cr2wmNP2n4deA.jpeg</url>
            <title>Stories by Randi Adhityas Saputra on Medium</title>
            <link>https://medium.com/@randiadhityassaputra?source=rss-902c700e3176------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 23:43:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@randiadhityassaputra/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[Caching with Redis: Fast Is Easy, Keeping It Correct Is the Hard Part]]></title>
            <link>https://medium.com/@randiadhityassaputra/caching-with-redis-fast-is-easy-keeping-it-correct-is-the-hard-part-62ee81d3837c?source=rss-902c700e3176------2</link>
            <guid isPermaLink="false">https://medium.com/p/62ee81d3837c</guid>
            <category><![CDATA[valkey]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[system-architecture]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Randi Adhityas Saputra]]></dc:creator>
            <pubDate>Fri, 11 Sep 2026 02:18:31 GMT</pubDate>
            <atom:updated>2026-09-11T02:18:31.596Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*VHRTpG_yiRTMccHpzDAmOA.png" /></figure><p>I used to think caching was pretty simple.</p><blockquote><em>“The database is slow? Just put Redis in front of it.”</em></blockquote><p>And honestly… it works. 😄</p><p>Until the database changes.</p><p>That’s when caching gets interesting.</p><p>Redis can make our application much faster, but it also introduces a new problem:</p><p><strong>What happens when the data in Redis is no longer the same as the data in the database?</strong></p><p>In this article, I’ll walk through how Redis caching works using a simple coffee app example, including:</p><ul><li>Cache-aside pattern</li><li>Cache HIT vs MISS</li><li>Latency comparison</li><li>Stale cache</li><li>Active invalidation</li><li>TTL</li><li>Using Redis for sessions</li></ul><p>The goal isn’t just to make the application faster.</p><p>It’s to make it <strong>fast without serving the wrong data</strong>.</p><h3>The Problem: Reading the Database Again and Again</h3><p>Imagine we have a coffee app.</p><p>A customer opens their profile:</p><pre>GET /customers/16</pre><p>Without caching, the request might look like this:</p><pre>Customer<br>   │<br>   ▼<br>Coffee API<br>   │<br>   ▼<br>PostgreSQL</pre><p>Every request goes directly to PostgreSQL.</p><p>Let’s say the database query takes around 30ms.</p><p>If the same customer refreshes their profile five times:</p><pre>Request → PostgreSQL → 31ms<br>Request → PostgreSQL → 29ms<br>Request → PostgreSQL → 32ms<br>Request → PostgreSQL → 30ms<br>Request → PostgreSQL → 31ms</pre><p>Nothing is necessarily wrong here.</p><p>But we’re doing the same database work over and over again.</p><p>And as traffic grows, this becomes expensive.</p><h3>Put Redis in Front of PostgreSQL</h3><p>This is where Redis comes in.</p><p>Instead of always going to PostgreSQL, the application checks Redis first.</p><pre>Customer<br>   │<br>   ▼<br>Coffee API<br>   │<br>   ▼<br>Redis<br>   │<br>   │ MISS<br>   ▼<br>PostgreSQL</pre><p>Redis stores frequently accessed data in memory.</p><p>For example:</p><pre>customer:16</pre><p>could contain:</p><pre>{<br>  &quot;id&quot;: 16,<br>  &quot;name&quot;: &quot;Randi&quot;,<br>  &quot;favorite_coffee&quot;: &quot;Espresso&quot;<br>}</pre><p>Now the application can reuse that data instead of querying PostgreSQL every time.</p><h3>Cache-Aside Pattern</h3><p>One of the most common approaches is called the <strong>cache-aside pattern</strong>.</p><p>The application itself manages the cache.</p><p>The basic flow is:</p><pre>              Request<br>                 │<br>                 ▼<br>            Check Redis<br>             /       \<br>           HIT       MISS<br>            │          │<br>            ▼          ▼<br>        Return      Query DB<br>        cached         │<br>                       ▼<br>                  Store in Redis<br>                       │<br>                       ▼<br>                  Return data</pre><p>Let’s break it down.</p><h3>First Request: Cache MISS</h3><p>The customer requests:</p><pre>GET /customers/16</pre><p>The application checks Redis:</p><pre>customer:16</pre><p>But the key doesn’t exist.</p><p>That’s a <strong>cache MISS</strong>.</p><p>The application then queries PostgreSQL.</p><pre>Redis<br>  │<br>  └── MISS<br>       │<br>       ▼<br>PostgreSQL</pre><p>PostgreSQL returns the customer profile.</p><p>The application stores the result in Redis:</p><pre>SET customer:16</pre><p>And finally returns the response.</p><p>The first request has to pay the database cost.</p><p>For example:</p><pre>CACHE MISS customer:16 -&gt; database (31ms)</pre><h3>Second Request: Cache HIT</h3><p>Now the customer refreshes the page.</p><p>The application checks Redis again:</p><pre>customer:16</pre><p>This time, the data exists.</p><p>That’s a <strong>cache HIT</strong>.</p><p>The application can return the value directly from Redis.</p><p>For example:</p><pre>CACHE HIT customer:16 (0.8ms)</pre><p>No PostgreSQL query is necessary.</p><p>The next requests might look like:</p><pre>CACHE MISS customer:16 -&gt; database (31ms)<br>CACHE HIT customer:16 (0.8ms)<br>CACHE HIT customer:16 (0.6ms)<br>CACHE HIT customer:16 (0.7ms)<br>CACHE HIT customer:16 (0.5ms)</pre><p>Now we can clearly see what’s happening.</p><p>The first request takes around 31ms because it needs the database.</p><p>The following requests are served from Redis in less than 1ms in this example.</p><h3>Why Is Redis Faster?</h3><p>The simple reason is that Redis is designed for very fast in-memory data access.</p><p>With PostgreSQL, the application is talking to a full relational database that has to handle things like:</p><ul><li>SQL parsing</li><li>Query planning</li><li>Index lookups</li><li>Transaction handling</li><li>Disk or buffer access</li><li>Relational processing</li></ul><p>Redis is much simpler for this use case.</p><p>The application essentially says:</p><pre>GET customer:16</pre><p>and Redis returns the stored value.</p><p>So the architecture changes from:</p><pre>Request<br>   │<br>   ▼<br>PostgreSQL<br>   │<br>   ▼<br>~30ms</pre><p>to:</p><pre>Request<br>   │<br>   ▼<br>Redis<br>   │<br>   ▼<br>&lt; 1ms</pre><p>The exact numbers depend on the environment.</p><p>Network latency, database load, Redis location, application code, and infrastructure all affect the result.</p><p>The important thing is the <strong>difference between the MISS and HIT path</strong>.</p><h3>Now We Have a New Problem</h3><p>At this point, caching looks amazing.</p><p>But let’s change something.</p><p>Suppose PostgreSQL contains:</p><pre>customer:16</pre><pre>favorite_coffee = &quot;Espresso&quot;</pre><p>Redis also contains:</p><pre>customer:16</pre><pre>favorite_coffee = &quot;Espresso&quot;</pre><p>Everything is consistent.</p><p>Now the customer changes their favorite coffee.</p><p>The application updates PostgreSQL:</p><pre>UPDATE customers<br>SET favorite_coffee = &#39;Cappuccino&#39;<br>WHERE id = 16;</pre><p>PostgreSQL now contains:</p><pre>Cappuccino</pre><p>But Redis still contains:</p><pre>Espresso</pre><p>Now we have:</p><pre>PostgreSQL<br>┌─────────────────────┐<br>│ Cappuccino          │<br>│ NEW VALUE           │<br>└─────────────────────┘</pre><pre>Redis<br>┌─────────────────────┐<br>│ Espresso            │<br>│ OLD VALUE           │<br>└─────────────────────┘</pre><p>The cache is now <strong>stale</strong>.</p><h3>The Dangerous Thing About Stale Cache</h3><p>Here’s what makes stale cache dangerous.</p><p>The application doesn’t necessarily know anything is wrong.</p><p>A request comes in:</p><pre>GET /customers/16</pre><p>Redis responds:</p><pre>CACHE HIT customer:16 (0.6ms)</pre><p>The application returns:</p><pre>favorite_coffee = Espresso</pre><p>But the database says:</p><pre>favorite_coffee = Cappuccino</pre><p>The request was fast.</p><p>The request succeeded.</p><p>There was no error.</p><p>But the answer was wrong.</p><p>That’s the real danger of caching.</p><blockquote><strong><em>A cache can make your application faster while making your data incorrect.</em></strong></blockquote><h3>Active Cache Invalidation</h3><p>So how do we solve this?</p><p>One common approach is <strong>active invalidation</strong>.</p><p>Whenever we change the database, we also remove the related cache entry.</p><p>For example:</p><pre>UPDATE customers<br>SET favorite_coffee = &#39;Cappuccino&#39;<br>WHERE id = 16;</pre><p>Then:</p><pre>DEL customer:16</pre><p>The flow becomes:</p><pre>              UPDATE<br>                │<br>                ▼<br>          PostgreSQL<br>                │<br>                ▼<br>        Invalidate Redis<br>                │<br>                ▼<br>        DEL customer:16</pre><p>Now Redis no longer contains the old value.</p><h3>What Happens on the Next Read?</h3><p>The customer requests their profile again:</p><pre>GET /customers/16</pre><p>The application checks Redis.</p><p>The key doesn’t exist.</p><p>So we get:</p><pre>CACHE MISS customer:16 -&gt; database (30ms)</pre><p>The application reads PostgreSQL.</p><p>PostgreSQL returns:</p><pre>Cappuccino</pre><p>The application puts the fresh data into Redis:</p><pre>SET customer:16</pre><p>And returns the current value.</p><p>The next request becomes:</p><pre>CACHE HIT customer:16 (0.7ms)</pre><p>So the complete lifecycle is:</p><pre>UPDATE DATABASE<br>       │<br>       ▼<br>DELETE CACHE<br>       │<br>       ▼<br>GET /customers/16<br>       │<br>       ▼<br>CACHE MISS<br>       │<br>       ▼<br>READ DATABASE<br>       │<br>       ▼<br>STORE FRESH DATA<br>       │<br>       ▼<br>CACHE HIT</pre><h3>Why Delete Instead of Updating Redis?</h3><p>You might ask:</p><blockquote><em>Why don’t we simply update Redis with the new value?</em></blockquote><p>That’s also possible.</p><p>But cache invalidation is often simpler.</p><p>Instead of making the application maintain two copies manually:</p><pre>PostgreSQL = new value<br>Redis      = new value</pre><p>we can make PostgreSQL the source of truth:</p><pre>PostgreSQL<br>    │<br>    │ update<br>    ▼<br>Delete Redis key</pre><p>Then the next read automatically rebuilds the cache.</p><p>This is especially useful when the cached object is large or complicated.</p><h3>TTL: Another Layer of Protection</h3><p>Active invalidation works well when the application knows when data changes.</p><p>But what if someone forgets to invalidate the cache?</p><p>This is where <strong>TTL</strong>, or Time To Live, becomes useful.</p><p>Instead of storing:</p><pre>customer:16</pre><p>forever, we give it an expiration time.</p><p>For example:</p><pre>customer:16<br>TTL = 60 seconds</pre><p>After 60 seconds, Redis automatically removes the entry.</p><p>Conceptually:</p><pre>Cache created<br>     │<br>     ▼<br>   0 sec<br>     │<br>     ▼<br>  30 sec<br>     │<br>     ▼<br>  60 sec<br>     │<br>     ▼<br>  EXPIRED</pre><p>The next request becomes a cache MISS.</p><p>The application then retrieves the current value from PostgreSQL.</p><h3>TTL Doesn’t Replace Invalidation</h3><p>It’s tempting to think:</p><blockquote><em>“If I use TTL, I don’t need invalidation.”</em></blockquote><p>Not necessarily.</p><p>Imagine:</p><pre>TTL = 1 hour</pre><p>The database changes one minute after the cache was created.</p><p>If you don’t invalidate the cache, users could see stale data for almost an hour.</p><p>That’s a long time for some applications.</p><p>Active invalidation handles known writes immediately.</p><p>TTL acts as a <strong>safety net</strong>.</p><p>A common strategy is:</p><pre>Write<br>  │<br>  ▼<br>Update database<br>  │<br>  ▼<br>Invalidate cache<br>  │<br>  ▼<br>Fresh cache on next read<br>  │<br>  ▼<br>TTL protects against missed invalidation</pre><h3>Redis Can Also Store Sessions</h3><p>Another interesting thing about Redis is that the same infrastructure can be used for login sessions.</p><p>For example:</p><pre>Redis<br>├── customer:16<br>│   └── Cached customer profile<br>│<br>├── session:abc123<br>│   └── Login session<br>│<br>└── session:def456<br>    └── Login session</pre><p>The application might use:</p><pre>customer:16</pre><p>for cached application data.</p><p>And:</p><pre>session:abc123</pre><p>for authentication state.</p><p>So Redis can effectively do double duty:</p><pre>Redis<br>├── Cache<br>└── Session Store</pre><p>Of course, in a production environment, you still need to think about memory limits, eviction policies, security, availability, and whether different workloads should share the same Redis instance.</p><h3>The Cache-Aside Lifecycle</h3><p>Putting everything together, the complete cache-aside lifecycle looks like this:</p><pre>                    READ<br>                     │<br>                     ▼<br>                  Redis<br>                 /     \<br>              HIT       MISS<br>               │          │<br>               ▼          ▼<br>          Return data   PostgreSQL<br>                           │<br>                           ▼<br>                      Store in Redis<br>                           │<br>                           ▼<br>                       Return data<br></pre><pre>                    WRITE<br>                     │<br>                     ▼<br>                 PostgreSQL<br>                     │<br>                     ▼<br>                DEL cache key<br>                     │<br>                     ▼<br>                Cache invalidated</pre><p>And TTL sits around the cached value:</p><pre>             ┌───────────────────┐<br>             │       Redis       │<br>             │                   │<br>             │   customer:16     │<br>             │                   │<br>             │      TTL          │<br>             │       ↓           │<br>             │    expires        │<br>             └───────────────────┘</pre><h3>The Trade-Off</h3><p>Caching gives us some great benefits:</p><pre>✓ Faster reads<br>✓ Lower database load<br>✓ Better scalability<br>✓ Better response times</pre><p>But we also introduce new complexity:</p><pre>✗ Another copy of the data<br>✗ Cache invalidation<br>✗ TTL configuration<br>✗ Memory management<br>✗ Possible stale reads<br>✗ More application logic</pre><p>That’s why I don’t think the right question is:</p><blockquote><em>“Can we add Redis?”</em></blockquote><p>The better question is:</p><blockquote><strong><em>“Is this data accessed frequently enough that caching is worth the complexity?”</em></strong></blockquote><h3>When Should You Cache?</h3><p>Caching usually makes sense for data that is:</p><ul><li>Read frequently</li><li>Relatively expensive to retrieve</li><li>Not changed constantly</li><li>Safe to temporarily cache</li><li>Requested repeatedly by many users</li></ul><p>For example:</p><pre>Product catalog<br>Customer profiles<br>Configuration<br>Popular content<br>Reference data<br>API responses</pre><p>But data that changes every second and absolutely must be real-time may require a different strategy.</p><h3>The Most Important Part: Correctness</h3><p>When I started looking at caching, the first thing that caught my attention was performance.</p><p>Something like:</p><pre>PostgreSQL → 30ms<br>Redis      → &lt;1ms</pre><p>That’s impressive.</p><p>But after seeing the stale-cache scenario, the more important question became:</p><blockquote><strong><em>How do we make sure the fast answer is still the correct answer?</em></strong></blockquote><p>That’s where cache invalidation comes in.</p><p>A good caching strategy should answer:</p><h3>1. When do we populate the cache?</h3><p>Usually on a cache MISS.</p><h3>2. When do we invalidate the cache?</h3><p>When the underlying data changes.</p><h3>3. How long should the cached value live?</h3><p>Use an appropriate TTL.</p><h3>4. What happens if invalidation fails?</h3><p>TTL should provide a bounded-staleness safety net.</p><h3>Final Takeaway</h3><p>Caching isn’t really difficult because Redis is complicated.</p><p>The difficult part is everything around it.</p><p>Getting this:</p><pre>Redis → 0.6ms</pre><p>instead of:</p><pre>PostgreSQL → 30ms</pre><p>is relatively easy.</p><p>The hard part is making sure that the 0.6ms response contains the <strong>right data</strong>.</p><p>The moment we introduce a cache, we introduce another copy of our data.</p><p>That means we need a strategy for keeping that copy fresh.</p><p>For me, the biggest lesson is:</p><blockquote><strong><em>A cache you never invalidate is just a bug with good latency.</em></strong></blockquote><p>Caching is easy.</p><p><strong>Keeping the cache correct is the real work.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62ee81d3837c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL Indexes: How One Index Made My Coffee App Faster ☕]]></title>
            <link>https://medium.com/@randiadhityassaputra/postgresql-indexes-how-one-index-made-my-coffee-app-faster-511de9ad174f?source=rss-902c700e3176------2</link>
            <guid isPermaLink="false">https://medium.com/p/511de9ad174f</guid>
            <category><![CDATA[database-indexing]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[optimize-query]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Randi Adhityas Saputra]]></dc:creator>
            <pubDate>Wed, 09 Sep 2026 03:51:47 GMT</pubDate>
            <atom:updated>2026-09-09T03:51:47.484Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*eh8OP6l0PiScKj4Sw4HtIw.png" /></figure><blockquote><strong>I recently ran into a simple database performance problem.</strong></blockquote><p>Imagine a coffee app with a PostgreSQL table containing <strong>1 million coffee orders</strong>.</p><p>The application needs to answer a simple question:</p><blockquote><em>“How many orders does customer #16 have?”</em></blockquote><p>So we run:</p><pre>SELECT count(*)<br>FROM coffee_orders<br>WHERE customer_id = 16;</pre><p>Seems simple enough.</p><p>But without an index, PostgreSQL may need to scan a huge number of rows to find the matching ones.</p><p>And that’s where things get interesting.</p><h3>The Problem: 1 Million Rows</h3><p>Let’s say our table looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*XyusNcs2pJqikzzX2lYN_g.png" /></figure><p>There are <strong>1 million rows</strong>, but maybe only around 1,000 belong to customer 16.</p><p>Without an index, PostgreSQL may do something like:</p><pre>1,000,000 rows<br>      ↓<br>check customer_id<br>      ↓<br>keep customer 16<br>      ↓<br>discard everything else</pre><p>Let’s see what PostgreSQL actually does:</p><pre>EXPLAIN ANALYZE<br>SELECT count(*)<br>FROM coffee_orders<br>WHERE customer_id = 16;</pre><p>You may see:</p><pre>Seq Scan on coffee_orders</pre><p>A <strong>Sequential Scan</strong> means PostgreSQL is scanning through the table to find matching rows.</p><p>It’s like having 1 million coffee receipts and asking:</p><blockquote><em>“Find customer #16.”</em></blockquote><p>Then checking them one by one. 😅</p><h3>Add an Index</h3><p>Now let’s give PostgreSQL a shortcut:</p><pre>CREATE INDEX coffee_orders_customer_id<br>ON coffee_orders(customer_id);</pre><p>This creates a <strong>B-tree index</strong> on customer_id.</p><p>Run the query again:</p><pre>EXPLAIN ANALYZE<br>SELECT count(*)<br>FROM coffee_orders<br>WHERE customer_id = 16;</pre><p>Now PostgreSQL may use:</p><pre>Index Scan</pre><p>or:</p><pre>Index Only Scan</pre><p>Instead of searching through the whole table, PostgreSQL can use the index to find the relevant entries.</p><p>Conceptually:</p><pre>WITHOUT INDEX</pre><pre>1,000,000 rows<br>      ↓<br>scan everything<br>      ↓<br>find customer 16<br></pre><pre>WITH INDEX</pre><pre>customer 16<br>     ↓<br>search index<br>     ↓<br>find matching rows</pre><p>That’s why an index can turn a slow query into a very fast one.</p><p>In my test, a query that took hundreds of milliseconds dropped to around <strong>1 ms</strong> after adding the right index.</p><p>Pretty impressive for one line of SQL. ☕</p><h3>But There’s a Catch</h3><p>At this point, you might think:</p><blockquote><em>“If indexes make queries faster, why don’t I index every column?”</em></blockquote><p>Because <strong>indexes aren’t free</strong>.</p><p>Every time we insert, update, or delete a row, PostgreSQL may also need to update the indexes.</p><p>For example:</p><pre>INSERT<br>   ↓<br>Update table<br>   ↓<br>Update customer_id index<br>   ↓<br>Update created_at index<br>   ↓<br>Update other indexes</pre><p>So indexes create a trade-off:</p><p>BenefitCost<strong>SELECT</strong>Faster — <strong>INSERT</strong> — Can be slower<strong>UPDATE</strong> — Can be slower<strong>DELETE</strong> — Can be slower<strong>Storage</strong> — Uses additional disk</p><p>The more indexes you create, the more maintenance PostgreSQL has to do.</p><h3>What Should I Index?</h3><p>Don’t start with:</p><blockquote><em>“Which columns can I index?”</em></blockquote><p>Start with:</p><blockquote><strong><em>“Which columns does my application actually query?”</em></strong></blockquote><p>Common candidates are columns used in:</p><h3>WHERE</h3><pre>SELECT *<br>FROM coffee_orders<br>WHERE customer_id = 16;</pre><h3>JOIN</h3><pre>SELECT *<br>FROM coffee_orders o<br>JOIN customers c<br>    ON o.customer_id = c.id;</pre><h3>ORDER BY</h3><pre>SELECT *<br>FROM coffee_orders<br>WHERE customer_id = 16<br>ORDER BY created_at DESC;</pre><p>For the last example, a composite index might help:</p><pre>CREATE INDEX coffee_orders_customer_created<br>ON coffee_orders(customer_id, created_at);</pre><p>The important thing is that the index matches the <strong>real query pattern</strong>.</p><h3>Do I Need to Index Everything?</h3><p><strong>No.</strong></p><p>A million-row table doesn’t mean you need a million indexes. 😄</p><p>You don’t need an index simply because a column exists.</p><p>For example:</p><pre>id<br>customer_id       ← frequently filtered<br>coffee_name<br>status<br>created_at        ← frequently sorted<br>description</pre><p>Maybe customer_id and created_at are important for your application&#39;s queries.</p><p>Maybe description isn&#39;t.</p><p>Index based on <strong>actual workload</strong>, not guesswork.</p><h3>How to See Your Indexes</h3><p>In PostgreSQL:</p><pre>\d coffee_orders</pre><p>Or:</p><pre>SELECT indexname, indexdef<br>FROM pg_indexes<br>WHERE tablename = &#39;coffee_orders&#39;;</pre><h3>How to Delete an Index</h3><p>If an index is no longer needed:</p><pre>DROP INDEX coffee_orders_customer_id;</pre><p>Then verify:</p><pre>\d coffee_orders</pre><h3>The Real Lesson</h3><p>The biggest lesson for me wasn’t simply:</p><blockquote><em>“Indexes make queries faster.”</em></blockquote><p>It’s:</p><blockquote><strong><em>Indexes are a trade-off.</em></strong></blockquote><p>A good index can help PostgreSQL avoid scanning millions of rows:</p><pre>1,000,000 rows<br>      ↓<br>      ❌</pre><p>and instead quickly locate what it needs:</p><pre>Index<br>  ↓<br>customer #16<br>  ↓<br>matching rows</pre><p>But every index also adds storage and write overhead.</p><p>So my rule of thumb is:</p><p><strong>Measure → Understand → Index → Measure again.</strong></p><p>Don’t index everything.</p><p>Index the things your application actually searches, joins, or sorts on.</p><p>And when in doubt, ask PostgreSQL:</p><pre>EXPLAIN ANALYZE</pre><p>Because the database usually knows exactly where the pain is. ☕</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=511de9ad174f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[☕ What Does a Load Balancer Actually Do? Let’s Explain It with Coffee]]></title>
            <link>https://medium.com/@randiadhityassaputra/what-does-a-load-balancer-actually-do-lets-explain-it-with-coffee-ff1867c75327?source=rss-902c700e3176------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff1867c75327</guid>
            <category><![CDATA[load-balancer]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[coffee]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Randi Adhityas Saputra]]></dc:creator>
            <pubDate>Wed, 09 Sep 2026 03:24:37 GMT</pubDate>
            <atom:updated>2026-09-09T03:24:37.916Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*Y7_fUKab6UrGT9M93wYPBA.png" /></figure><p>I like coffee.</p><p>So instead of explaining load balancing with the usual “Server A, Server B, Client C” diagrams, let’s talk about coffee.</p><p>Imagine your favorite coffee shop.</p><p>You walk in, place your order, and say:</p><blockquote><em>“One iced latte, please.” ☕</em></blockquote><p>You don’t really care <strong>which barista</strong> makes your coffee.</p><p>You just want your coffee.</p><p>Behind the counter, there might be two, three, or even ten baristas working.</p><p>And somehow, the orders need to be distributed between them.</p><p>Sounds familiar?</p><p>That’s basically what a <strong>load balancer</strong> does.</p><h3>☕ The Coffee Shop</h3><p>Let’s start with a very simple coffee shop.</p><p>There are two baristas:</p><pre>              Customer<br>                  |<br>                  | &quot;One latte, please!&quot;<br>                  v<br>          ┌─────────────────┐<br>          │   Front Counter │<br>          └────────┬────────┘<br>                   |<br>             ┌─────┴─────┐<br>             |           |<br>             v           v<br>        ┌─────────┐ ┌─────────┐<br>        │Barista 1│ │Barista 2│<br>        └─────────┘ └─────────┘</pre><p>The customer talks to the <strong>front counter</strong>.</p><p>The front counter decides which barista should make the coffee.</p><p>Maybe:</p><pre>Customer 1 ---&gt; Barista 1<br>Customer 2 ---&gt; Barista 2<br>Customer 3 ---&gt; Barista 1<br>Customer 4 ---&gt; Barista 2</pre><p>The customer doesn’t need to know anything about the baristas.</p><p>That’s the key idea behind load balancing.</p><h3>So What Is the Load Balancer?</h3><p>In our coffee shop:</p><pre>Front Counter = Load Balancer<br>Baristas      = Backend Servers<br>Customer      = Client<br>Coffee Order  = HTTP Request<br>Coffee        = HTTP Response</pre><p>In a real application:</p><pre>                    Client<br>                       |<br>                       v<br>                ┌─────────────┐<br>                │Load Balancer│<br>                └──────┬──────┘<br>                       |<br>                ┌──────┴──────┐<br>                |             |<br>                v             v<br>             Backend 1     Backend 2</pre><p>The load balancer receives the request and decides where it should go.</p><p>In our lab, we’ll use <strong>NGINX</strong> as that front counter.</p><h3>☕ Let’s Build Our Coffee Shop</h3><p>For the lab, we’ll create:</p><ul><li>coffee-shop-net — our private coffee shop network</li><li>barista-01 — first backend</li><li>barista-02 — second backend</li><li>coffee-lb — our NGINX load balancer</li><li>Port 9090 — the public entrance to our coffee shop</li></ul><p>The architecture will look like this:</p><pre>                          Customer ☕<br>                             |<br>                             | :9090<br>                             v<br>                     ┌──────────────┐<br>                     │   coffee-lb  │<br>                     │     NGINX    │<br>                     │ Front Counter│<br>                     └───────┬──────┘<br>                             |<br>                     coffee-shop-net<br>                       ┌─────┴─────┐<br>                       |           |<br>                       v           v<br>                ┌────────────┐ ┌────────────┐<br>                │ barista-01 │ │ barista-02 │<br>                │    :8080   │ │    :8080   │<br>                └────────────┘ └────────────┘</pre><p>Now let’s build it.</p><h3>Step 1 — Create Our Coffee Shop Network</h3><p>First:</p><pre>docker network create coffee-shop-net</pre><p>Think of this as building the private area behind the coffee counter.</p><p>Customers don’t need access to this network.</p><p>The baristas and the front counter can communicate with each other.</p><p>Docker also provides internal DNS for containers on the same network.</p><p>So instead of remembering IP addresses, we can say:</p><pre>barista-01:8080<br>barista-02:8080</pre><p>Much easier.</p><p>And just like a real coffee shop, we don’t want to keep track of where every barista is physically standing.</p><p>We just know their names.</p><h3>Step 2 — Start Our Baristas</h3><p>Let’s start our first coffee-making backend:</p><pre>docker run -d \<br>  --name barista-01 \<br>  --network coffee-shop-net \<br>  coffeeapp:v1</pre><p>Then the second:</p><pre>docker run -d \<br>  --name barista-02 \<br>  --network coffee-shop-net \<br>  coffeeapp:v1</pre><p>Now we have:</p><pre>              coffee-shop-net<br>                 /        \<br>                /          \<br>               v            v<br>        barista-01     barista-02<br>           :8080          :8080</pre><p>Notice something important.</p><p>We aren’t publishing their ports to the host.</p><p>There is no:</p><pre>-p 8081:8080</pre><p>and no:</p><pre>-p 8082:8080</pre><p>Why?</p><p>Because customers don’t need to walk directly into the kitchen.</p><p>They go through the front counter.</p><h3>☕ Don’t Let Customers Into the Kitchen</h3><p>This is actually a useful infrastructure concept.</p><p>Imagine the coffee shop has:</p><pre>Front Counter<br>     |<br>     v<br>   Kitchen</pre><p>Customers shouldn’t be wandering around the kitchen.</p><p>Similarly, our architecture is:</p><pre>Internet<br>   |<br>   v<br>NGINX<br>   |<br>   v<br>Private Backend Network<br>   |<br>   ├── barista-01<br>   └── barista-02</pre><p>Only NGINX needs to be exposed externally.</p><p>The backend services can remain private.</p><p>This gives us a cleaner architecture and reduces the number of things directly exposed to the outside world.</p><h3>Step 3 — Configure NGINX</h3><p>Now we need to tell our front counter where the baristas are.</p><p>In NGINX, we do this with an upstream block:</p><pre>upstream coffee_backend {<br>    server barista-01:8080;<br>    server barista-02:8080;<br>}</pre><p>Think of this as giving the cashier a list:</p><pre>Coffee orders can go to:</pre><pre>☕ Barista 01<br>☕ Barista 02</pre><p>Then we tell NGINX:</p><pre>location / {<br>    proxy_pass http://coffee_backend;<br>}</pre><p>In simple terms:</p><blockquote><em>“When a customer places an order, send it to one of the available baristas.”</em></blockquote><p>Our configuration becomes:</p><pre>upstream coffee_backend {<br>    server barista-01:8080;<br>    server barista-02:8080;<br>}</pre><pre>server {<br>    listen 80;</pre><pre>    location / {<br>        proxy_pass <a href="http://coffee_backend;/">http://coffee_backend;</a><br>    }<br>}</pre><p>That’s our coffee shop front counter.</p><h3>Step 4 — Start the NGINX Load Balancer</h3><p>Now let’s start NGINX:</p><pre>docker run -d \<br>  --name coffee-lb \<br>  --network coffee-shop-net \<br>  -p 9090:80 \<br>  -v /root/lab1/nginx.conf:/etc/nginx/nginx.conf:ro \<br>  nginx:alpine</pre><p>The important part is:</p><pre>Host :9090<br>      |<br>      v<br>coffee-lb :80</pre><p>So when we visit:</p><pre>http://localhost:9090</pre><p>we’re actually talking to the NGINX load balancer.</p><h3>☕ Place Your First Order</h3><p>Let’s test it:</p><pre>curl http://localhost:9090</pre><p>Our request travels like this:</p><pre>Customer<br>   |<br>   | &quot;One coffee!&quot;<br>   v<br>coffee-lb<br>   |<br>   | NGINX<br>   v<br>barista-01<br>   |<br>   | &quot;Coffee ready!&quot;<br>   v<br>coffee-lb<br>   |<br>   v<br>Customer</pre><p>Simple.</p><p>But now let’s order several coffees.</p><h3>☕ Ten Coffees, Please!</h3><p>Run:</p><pre>for i in {1..10}; do<br>    curl -s http://localhost:9090<br>    echo<br>done</pre><p>If our application identifies which backend handled the request, we’ll see requests going to both baristas.</p><p>Something like:</p><pre>Request 1 ---&gt; barista-01<br>Request 2 ---&gt; barista-02<br>Request 3 ---&gt; barista-01<br>Request 4 ---&gt; barista-02<br>Request 5 ---&gt; barista-01<br>Request 6 ---&gt; barista-02</pre><p>This is the basic <strong>round-robin</strong> behavior.</p><p>The front counter alternates between the available baristas.</p><h3>What If One Barista Is Busy?</h3><p>Now imagine Barista 1 suddenly gets overwhelmed.</p><p>There are ten customers waiting.</p><pre>Front Counter<br>                     |<br>              ┌──────┴──────┐<br>              |             |<br>              v             v<br>        ☕ Barista 1    ☕ Barista 2<br>          BUSY 😰          OK 😎</pre><p>A good traffic distribution system shouldn’t blindly keep sending work to a backend that isn’t responding properly.</p><p>This is where availability and failure handling become important.</p><p>Let’s simulate a failure.</p><p>Stop Barista 1:</p><pre>docker stop barista-01</pre><p>Now:</p><pre>                NGINX<br>                 |<br>          ┌──────┴──────┐<br>          |             |<br>          X             |<br>          |             v<br>     barista-01     barista-02<br>       CLOSED          OPEN</pre><p>Send another request:</p><pre>curl http://localhost:9090</pre><p>NGINX can detect upstream connection failures and temporarily avoid an unavailable backend.</p><p>The coffee shop is still operating.</p><p>One barista went home.</p><p>The shop didn’t have to close.</p><h3>☕ This Is High Availability</h3><p>And this is one of the biggest reasons we use load balancers.</p><p>Without a load balancer:</p><pre>Customer<br>   |<br>   v<br>Barista 1<br>   |<br>   X<br>  DEAD</pre><p>The entire application might become unavailable.</p><p>With a load balancer:</p><pre>                 NGINX<br>                /     \<br>               X       |<br>               |       v<br>          Barista 1  Barista 2<br>            DEAD       OK</pre><p>The system can continue serving requests through the remaining backend.</p><p>That’s the basic idea of <strong>high availability</strong>.</p><h3>What If the Coffee Shop Gets Crazy Busy?</h3><p>Let’s say we open a new coffee shop.</p><p>At first:</p><pre>2 baristas</pre><p>Everything is fine.</p><p>Then suddenly everyone discovers our coffee.</p><p>☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕</p><p>Now two baristas aren’t enough.</p><p>So we hire more.</p><pre>                 NGINX<br>                   |<br>        ┌──────────┼──────────┐<br>        |          |          |<br>        v          v          v<br>    Barista 1  Barista 2  Barista 3</pre><p>And later:</p><pre>                 NGINX<br>                   |<br>       ┌───────────┼───────────┐<br>       |           |           |<br>       v           v           v<br>    Barista 1   Barista 2   Barista 3<br>       |           |           |<br>       v           v           v<br>    Barista 4   Barista 5   Barista 6</pre><p>That’s <strong>horizontal scaling</strong>.</p><p>Instead of making one barista work faster and faster, we add more baristas.</p><p>In infrastructure terms:</p><blockquote><em>Add more application instances instead of making one server bigger.</em></blockquote><h3>☕ This Is What Happens in Production</h3><p>Our little coffee shop might look like this:</p><pre>Customer<br>   |<br>   v<br>NGINX<br>   |<br>   ├── barista-01<br>   └── barista-02</pre><p>A real production application might look like:</p><pre>                        Internet<br>                           |<br>                           v<br>                  Cloud Load Balancer<br>                           |<br>              ┌────────────┼────────────┐<br>              |            |            |<br>              v            v            v<br>           App 01       App 02       App 03<br>              |            |            |<br>              └────────────┼────────────┘<br>                           |<br>                        Database</pre><p>The technology might be different.</p><p>Maybe it’s:</p><ul><li>AWS Load Balancer</li><li>Google Cloud Load Balancer</li><li>Azure Load Balancer</li><li>NGINX</li><li>HAProxy</li><li>Kubernetes Service</li><li>Gateway API</li></ul><p>But the fundamental idea is still:</p><pre>Customer<br>   |<br>   v<br>Front Counter<br>   |<br>   +---- Barista 1<br>   +---- Barista 2<br>   +---- Barista 3</pre><h3>The Customer Doesn’t Care Which Barista Made the Coffee</h3><p>This is probably the most important concept.</p><p>Imagine ordering a latte.</p><p>You don’t ask:</p><blockquote><em>“Was Barista 1 or Barista 2 responsible for this coffee?”</em></blockquote><p>You just care that:</p><pre>☕ Coffee arrives</pre><p>That’s exactly what we want from our application.</p><p>The client shouldn’t need to know:</p><pre>10.10.1.21<br>10.10.1.22<br>10.10.1.23</pre><p>Instead, the client talks to:</p><pre>https://coffee.example.com</pre><p>The infrastructure handles everything behind the scenes.</p><p>This is <strong>decoupling</strong>.</p><h3>☕ What About HTTPS?</h3><p>Our coffee shop can also have a secure front door.</p><p>Instead of:</p><pre>Customer<br>   |<br> HTTP<br>   v<br> NGINX</pre><p>we can have:</p><pre>Customer<br>   |<br> HTTPS 🔒<br>   v<br>NGINX<br>   |<br>   v<br>Backend</pre><p>NGINX can terminate TLS.</p><p>The backend doesn’t necessarily need to handle the public TLS connection.</p><p>This is commonly called <strong>TLS termination</strong>.</p><h3>☕ What About Different Menus?</h3><p>Maybe our coffee shop has different departments.</p><p>For example:</p><pre>/coffee/*<br>/food/*<br>/orders/*</pre><p>NGINX can route these differently:</p><pre>/coffee/*  ---&gt; Coffee API<br>/food/*    ---&gt; Food API<br>/orders/*  ---&gt; Order API</pre><p>Now NGINX isn’t just a load balancer.</p><p>It’s also acting as a <strong>reverse proxy and traffic router</strong>.</p><h3>☕ A Real Production Coffee Shop</h3><p>Let’s imagine we’re building a very successful coffee delivery application.</p><p>Customers use:</p><pre>coffee.example.com</pre><p>The architecture could look like:</p><pre>                          Customers<br>                             |<br>                             v<br>                    ┌─────────────────┐<br>                    │ Load Balancer   │<br>                    │      NGINX      │<br>                    └────────┬────────┘<br>                             |<br>               ┌─────────────┼─────────────┐<br>               |             |             |<br>               v             v             v<br>          Coffee API     Coffee API     Coffee API<br>             #1             #2             #3<br>               |             |             |<br>               └─────────────┼─────────────┘<br>                             |<br>                          Database</pre><p>During normal traffic:</p><pre>3 application instances</pre><p>During a huge promotion:</p><pre>3 ---&gt; 10 application instances</pre><p>After the promotion:</p><pre>10 ---&gt; 3 application instances</pre><p>The customers don’t need to know any of this.</p><p>They still visit:</p><pre>coffee.example.com</pre><p>The front door stays the same.</p><p>The kitchen can change.</p><h3>The Bigger Infrastructure Lesson</h3><p>This coffee example might sound silly.</p><p>But that’s actually why it’s useful.</p><p>When learning infrastructure, it’s easy to get lost in:</p><ul><li>IP addresses</li><li>ports</li><li>DNS</li><li>containers</li><li>reverse proxies</li><li>health checks</li><li>TLS</li><li>routing</li><li>scaling</li></ul><p>The coffee shop gives us a simple mental model.</p><pre>Customer<br>   |<br>   v<br>Front Counter<br>   |<br>   +---- Barista<br>   |<br>   +---- Barista<br>   |<br>   +---- Barista</pre><p>Translate that into infrastructure:</p><pre>Client<br>   |<br>   v<br>Load Balancer<br>   |<br>   +---- Backend<br>   |<br>   +---- Backend<br>   |<br>   +---- Backend</pre><p>Same idea.</p><p>Different coffee. ☕</p><h3>☕ Final Architecture</h3><p>Our Docker lab ends up looking like this:</p><pre>                          Customer<br>                            |<br>                            | :9090<br>                            v<br>                    ┌──────────────┐<br>                    │   coffee-lb  │<br>                    │     NGINX    │<br>                    │ Front Counter│<br>                    └───────┬──────┘<br>                            |<br>                     coffee-shop-net<br>                       ┌────┴────┐<br>                       |         |<br>                       v         v<br>                ┌────────────┐ ┌────────────┐<br>                │ barista-01 │ │ barista-02 │<br>                │    :8080   │ │    :8080   │<br>                └────────────┘ └────────────┘</pre><p>And our NGINX configuration is just:</p><pre>upstream coffee_backend {<br>    server barista-01:8080;<br>    server barista-02:8080;<br>}</pre><pre>server {<br>    listen 80;</pre><pre>    location / {<br>        proxy_pass <a href="http://coffee_backend;/">http://coffee_backend;</a><br>    }<br>}</pre><p>Pretty small, right?</p><p>But behind those few lines is a very important infrastructure concept.</p><h3>Final Sip ☕</h3><p>A load balancer isn’t just something that “splits traffic.”</p><p>It gives us a <strong>stable front door</strong> while allowing the infrastructure behind it to change.</p><p>We can:</p><ul><li>add more backend servers</li><li>remove servers</li><li>replace failed servers</li><li>distribute traffic</li><li>route requests</li><li>terminate TLS</li><li>improve availability</li><li>scale horizontally</li></ul><p>Just like a busy coffee shop.</p><p>The customer sees one counter.</p><p>Behind that counter, there might be two baristas today, ten tomorrow, and fifty during the morning rush.</p><p>The customer doesn’t care.</p><p>They just want their coffee.</p><p>And that’s pretty much how we want our applications to behave too.</p><p><strong>One stable endpoint. Multiple replaceable backends.</strong></p><p>Now, who’s ready for coffee? ☕</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff1867c75327" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Google Maps to Gemini: How One API Key Created a $375,000 Cloud Bill]]></title>
            <link>https://medium.com/@randiadhityassaputra/from-google-maps-to-gemini-how-one-api-key-created-a-375-000-cloud-bill-c830199e96d7?source=rss-902c700e3176------2</link>
            <guid isPermaLink="false">https://medium.com/p/c830199e96d7</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[gemini-api]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[api-key]]></category>
            <dc:creator><![CDATA[Randi Adhityas Saputra]]></dc:creator>
            <pubDate>Tue, 25 Aug 2026 06:53:57 GMT</pubDate>
            <atom:updated>2026-08-25T06:53:57.902Z</atom:updated>
            <content:encoded><![CDATA[<h4>A security incident that started with a simple API key and ended with a financial impact of nearly Rp6 billion.</h4><p>Sometimes the most expensive cloud incidents don’t start with a sophisticated attack.</p><p>There was no zero-day vulnerability.</p><p>No compromised service account.</p><p>No complex infrastructure breach.</p><p>In this case, the problem was something much simpler:</p><p><strong>An API key that was never supposed to be used for AI was left unrestricted.</strong></p><p>The key had originally been used for public-facing services such as Google Maps or YouTube. At some point, it became exposed and compromised.</p><p>Then the project enabled the Gemini API.</p><p>Because the API key belonged to the same Google Cloud project and wasn’t properly restricted, an attacker could use that key to generate Gemini API requests.</p><blockquote>The result was a <strong>massive and unexpected financial impac</strong>t.</blockquote><p>Within only a few days, the project accumulated approximately <strong>Rp6 billion in API charges</strong> — roughly <strong>US$350,000–$400,000</strong>, depending on the exchange rate.</p><p>This incident was a painful reminder that an API key is not just an application configuration value.</p><blockquote><strong>In a cloud environment, an exposed credential can become a direct path to your billing account.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sqk4Q5537q9UkdZg1cBb_g.png" /></figure><h3>The Background: A Project With More History Than Anyone Expected</h3><p>Like many long-running cloud projects, this project had accumulated API keys over time.</p><p>Some were actively used.</p><p>Some belonged to older applications.</p><p>Some had been created for services such as:</p><ul><li>Google Maps</li><li>YouTube APIs</li><li>Firebase</li><li>Other public-facing Google APIs</li></ul><p>The problem wasn’t necessarily that these APIs existed.</p><p>The problem was that some keys had survived without proper restrictions.</p><p>An API key can be configured with restrictions that limit:</p><ol><li><strong>Who can use the key</strong></li></ol><ul><li>Website referrers</li><li>IP addresses</li><li>Android applications</li><li>iOS applications</li></ul><p><strong>2. Which APIs the key can call</strong></p><ul><li>Google Maps APIs</li><li>YouTube Data API</li><li>Other explicitly approved APIs</li></ul><p>But a legacy key can sometimes remain in an unrestricted state.</p><p>And if that key is exposed somewhere public — such as:</p><pre>Frontend JavaScript<br>Mobile application<br>Public Git repository<br>Old source code<br>Client-side configuration<br>Historical deployment artifact</pre><p>— it should be considered potentially compromised.</p><p>The dangerous part came later.</p><h3>Then Gemini API Was Enabled</h3><p>The project eventually enabled the Gemini API.</p><p>From the application’s perspective, this seemed unrelated to the existing Maps or YouTube API keys.</p><p>But from the perspective of the Google Cloud project, those credentials and APIs were now part of the same environment.</p><p>The simplified situation looked like this:</p><pre>GOOGLE CLOUD PROJECT<br>┌─────────────────────────────────────────────────────┐<br>│                                                     │<br>│   Existing API Key                                  │<br>│   ┌──────────────────────────────┐                  │<br>│   │ API Key: ABC123...           │                  │<br>│   │                              │                  │<br>│   │ Application Restriction: ❌  │                  │<br>│   │ API Restriction: ❌          │                  │<br>│   └──────────────┬───────────────┘                  │<br>│                  │                                  │<br>│                  │ Can potentially call             │<br>│                  ▼                                  │<br>│        ┌───────────────────────┐                    │<br>│        │ Google APIs          │                    │<br>│        │                       │                    │<br>│        │ Maps                  │                    │<br>│        │ YouTube               │                    │<br>│        │ Gemini API  ← NEW     │                    │<br>│        └───────────┬───────────┘                    │<br>│                    │                                │<br>└────────────────────┼────────────────────────────────┘<br>                     │<br>                     ▼<br>               ATTACKER / ABUSER<br>                     │<br>                     ▼<br>              Gemini API Requests<br>                     │<br>                     ▼<br>                💸 BILLING SPIKE</pre><p>The attacker didn’t need access to the Cloud Console.</p><p>They didn’t need a service account.</p><p>They didn’t need IAM permissions.</p><p>They only needed a usable API key.</p><p>And because the key had no proper API restrictions, it became possible to abuse it against an expensive AI service enabled within the same project.</p><h3>The Financial Impact</h3><p>The abuse did not look like a normal application workload.</p><p>Gemini API usage can consume requests and tokens extremely quickly.</p><p>Rate limits help regulate usage through dimensions such as requests per minute, tokens per minute, and requests per day, but rate limits are not the same thing as a hard financial budget. They also depend on the project’s usage tier and the model being used.</p><p>In this incident, the attacker was able to generate enough usage that the financial impact reached approximately:</p><blockquote><strong><em>Rp6,000,000,000</em></strong></blockquote><p>Using a rough exchange rate of Rp16,000 per US dollar, that is approximately:</p><blockquote><strong><em>US$375,000</em></strong></blockquote><p>And the most alarming part was not just the total.</p><p>It was the speed.</p><p>A cloud bill that normally grows gradually can change dramatically when an exposed credential is used to access a high-consumption generative AI service.</p><p>Traditional monitoring is often designed around infrastructure.</p><p>CPU spikes.</p><p>Memory spikes.</p><p>Disk utilization.</p><p>Network traffic.</p><p>But generative AI introduces a different type of risk.</p><p>A relatively small number of API clients can generate enormous cost depending on:</p><ul><li>Model selection</li><li>Input token size</li><li>Output token size</li><li>Request volume</li><li>Context window size</li><li>Batch or automated workloads</li></ul><p>This means:</p><blockquote><strong><em>A credential security incident can become a FinOps incident almost immediately.</em></strong></blockquote><h3>The Root Cause Was Not Gemini</h3><p>It would be easy to describe this as a “Gemini problem.”</p><p>But that would miss the actual lesson.</p><p>The root cause was a combination of several conditions.</p><h3>1. An API Key Was Exposed</h3><p>The key was available somewhere it should not have been.</p><p>Once an API key is exposed publicly, you should assume that someone else may already have a copy.</p><p>Deleting the repository later doesn’t necessarily solve the problem.</p><p>Removing the key from the current version of the application doesn’t guarantee that the key was never harvested.</p><p>Secrets have a long memory.</p><h3>2. The API Key Was Unrestricted</h3><p>The key lacked proper restrictions.</p><p>Instead of allowing only the intended API, the credential had broader access than necessary.</p><p>For example, a safer configuration for a Maps key would look conceptually like this:</p><pre>API Key<br>Allowed Application:<br>✓ example.com<br>Allowed APIs:<br>✓ Maps JavaScript API<br>✓ Places API<br>Not Allowed:<br>✗ Gemini API<br>✗ Generative Language API<br>✗ Other unrelated APIs</pre><p>But an unrestricted key effectively creates a much larger blast radius.</p><h3>3. Gemini API Was Enabled in the Same Project</h3><p>This was the missing piece that connected an old API key to a new financial risk.</p><p>The project contained:</p><pre>Legacy API Key<br>        +<br>No API Restriction<br>        +<br>Gemini API Enabled<br>        =<br>Potential Credential Abuse</pre><p>The API key may have been created years earlier for a completely different purpose.</p><p>But cloud projects evolve.</p><p>New APIs are enabled.</p><p>New services are introduced.</p><p>Old credentials remain.</p><p>And suddenly a credential that once represented a relatively small risk can become much more valuable to an attacker.</p><h3>The Three-Condition Risk Model</h3><p>The incident can be simplified into three conditions.</p><p>You should consider a project at risk if all three are true:</p><h3>1. An API Key Is Exposed</h3><p>For example:</p><ul><li>Public frontend</li><li>Mobile application</li><li>GitHub repository</li><li>GitLab repository</li><li>Old repository history</li><li>Public configuration file</li></ul><h3>2. The API Key Is Unrestricted</h3><p>The key does not have sufficient:</p><ul><li>Application restrictions</li><li>API restrictions</li></ul><h3>3. Gemini API Is Available in the Same Project</h3><p>The project can accept Gemini API usage that could potentially be associated with that credential.</p><pre>                ┌──────────────────┐<br>                │  Exposed Key     │<br>                └────────┬─────────┘<br>                         │<br>                         ▼<br>                ┌──────────────────┐<br>                │ Unrestricted     │<br>                │ API Access       │<br>                └────────┬─────────┘<br>                         │<br>                         ▼<br>                ┌──────────────────┐<br>                │ Gemini API       │<br>                │ Available        │<br>                └────────┬─────────┘<br>                         │<br>                         ▼<br>                  HIGH RISK<br>                         │<br>                         ▼<br>                    💸 BILLING</pre><p>Individually, each condition may not immediately create a disaster.</p><p>Together, they can create a very expensive incident.</p><h3>Why Budget Alerts Were Not Enough</h3><p>This is another important part of the story.</p><p>Traditional Cloud Billing budgets are primarily an alerting mechanism.</p><p>They tell you that spending has crossed a threshold.</p><p>But an alert is not the same thing as stopping the workload.</p><p>Google’s documentation explicitly distinguishes alerts-only budgets from spend caps: alerts-only budgets notify you, but do not automatically stop usage or spending.</p><p>At the time of this incident, the available protection was much more limited.</p><p>You could create something like:</p><pre>50% Budget<br>     │<br>     ▼<br>📧 Email Alert<br>80% Budget<br>     │<br>     ▼<br>📧 Email Alert<br>100% Budget<br>     │<br>     ▼<br>📧 Email Alert</pre><p>But the API could continue receiving requests.</p><p>If the attacker was generating requests faster than the billing data was being processed and reviewed, the financial damage could continue growing.</p><p>This is one of the difficult realities of cloud cost management:</p><blockquote><strong><em>Visibility is not the same as enforcement.</em></strong></blockquote><h3>Three Months Later, Google Introduced a New Safety Net</h3><p>The timing is interesting.</p><p>Google Cloud has since introduced <strong>Spend Cap Budgets</strong>, currently available as a Preview feature for eligible services.</p><p>For supported services, including Gemini API, a spend cap can automatically pause new usage when the configured spending threshold is reached. Google Cloud also notes that enforcement uses estimated costs and is not instantaneous, so some overage can still occur.</p><p>Conceptually, the protection now looks like this:</p><pre>Gemini API Usage<br>       │<br>       ▼<br>┌──────────────────────┐<br>│ Monthly Spend Cap    │<br>│                      │<br>│ Limit: $10,000       │<br>└──────────┬───────────┘<br>           │<br>           │ Spend reaches limit<br>           ▼<br>┌──────────────────────┐<br>│ SPEND CAP ENFORCED   │<br>│                      │<br>│ New Gemini API       │<br>│ usage is paused      │<br>└──────────────────────┘</pre><p>This is significantly different from a normal budget alert.</p><p>Instead of:</p><blockquote><em>“Your spending has exceeded the budget.”</em></blockquote><p>The system can move closer to:</p><blockquote><em>“The spending threshold has been reached, so new billable usage is paused.”</em></blockquote><p>According to the current documentation, spend caps can be configured for a single project and a single eligible service, and Gemini API is among the supported services. The service remains paused until the cap is manually lifted.</p><p>This would not replace credential security.</p><p>And it would not guarantee a bill of exactly zero beyond the cap because enforcement is not instantaneous.</p><p>But it adds an important financial circuit breaker.</p><h3>Rate Limits Are Not a Financial Firewall</h3><p>Another important lesson from this incident is that rate limiting and cost limiting solve different problems.</p><p>Gemini API rate limits control dimensions such as:</p><pre>RPM  → Requests Per Minute<br>TPM  → Tokens Per Minute<br>RPD  → Requests Per Day</pre><p>There are also spend-based rate limits tied to usage tiers.</p><p>But none of these should be treated as your only protection against unexpected financial exposure.</p><p>A system can remain technically within its permitted API rate limits and still generate a large bill.</p><p>For cloud engineers, these are different layers:</p><pre>┌────────────────────────────────────┐<br>│ Layer 1                            │<br>│ Credential Security                │<br>│                                    │<br>│ Restrict API Keys                  │<br>├────────────────────────────────────┤<br>│ Layer 2                            │<br>│ API Restrictions                   │<br>│                                    │<br>│ Allow Only Required APIs           │<br>├────────────────────────────────────┤<br>│ Layer 3                            │<br>│ Application Restrictions           │<br>│                                    │<br>│ Referrer / IP / Mobile App         │<br>├────────────────────────────────────┤<br>│ Layer 4                            │<br>│ Rate Limits and Quotas             │<br>│                                    │<br>│ Control Request Volume             │<br>├────────────────────────────────────┤<br>│ Layer 5                            │<br>│ Cost Monitoring                    │<br>│                                    │<br>│ Budgets + Anomaly Detection        │<br>├────────────────────────────────────┤<br>│ Layer 6                            │<br>│ Financial Circuit Breaker          │<br>│                                    │<br>│ Spend Cap                          │<br>└────────────────────────────────────┘</pre><p>Security and FinOps need to work together.</p><h3>The Immediate Response</h3><p>When investigating an incident like this, the first priority is to stop the abuse.</p><p>The response should generally look like this:</p><h3>Step 1: Identify the Source of Consumption</h3><p>Start with:</p><ul><li>Cloud Billing reports</li><li>Service-level cost breakdown</li><li>Gemini API usage</li><li>API key usage</li><li>Relevant logs and request patterns</li></ul><p>Look for abnormal behavior such as:</p><pre>Normal<br>───────▁▁▁▂▂▂▁▁▂</pre><pre>Abnormal<br>───────▁▁▁▂██████████</pre><p>The important question is:</p><blockquote><em>Which project, service, credential, and workload is generating the cost?</em></blockquote><h3>Step 2: Revoke or Rotate the Compromised Key</h3><p>Do not simply hide the key.</p><p>Do not assume changing a frontend configuration is enough.</p><p>If the key is compromised:</p><pre>OLD KEY<br>   │<br>   ▼<br>REVOKE / DELETE<br>   │<br>   ▼<br>CREATE NEW KEY<br>   │<br>   ▼<br>APPLY RESTRICTIONS<br>   │<br>   ▼<br>DEPLOY SAFELY</pre><p>Treat the old key as permanently compromised.</p><h3>Step 3: Restrict Every Remaining API Key</h3><p>Every key should answer two questions:</p><h3>Who is allowed to use this key?</h3><p>For example:</p><pre>Website:<br>example.com<br>Server:<br>203.x.x.x/32<br>Android:<br>Package + SHA certificate<br>iOS:<br>Bundle ID</pre><h3>Which APIs is this key allowed to call?</h3><p>For example:</p><pre>Maps Key<br>✓ Maps JavaScript API<br>✓ Places API<br>✗ Gemini API<br>✗ Generative Language API<br>✗ YouTube API<br>✗ Everything else</pre><p>The principle is simple:</p><blockquote><strong><em>One key should have one clear purpose.</em></strong></blockquote><h3>A Better Architecture: Don’t Share Public API Keys With AI Workloads</h3><p>One of the biggest architectural lessons from this incident is separation.</p><p>Instead of this:</p><pre>        ONE GOOGLE CLOUD PROJECT<br>        ┌───────────────────────────────┐<br>        │                               │<br>        │ Public API Keys               │<br>        │        │                      │<br>        │        ├── Maps               │<br>        │        ├── YouTube            │<br>        │        └── Gemini             │<br>        │                               │<br>        │ Same Project                  │<br>        │ Same Billing Exposure         │<br>        └───────────────────────────────┘</pre><p>Consider stronger separation:</p><pre>PROJECT A<br>Public Application APIs<br><br>Maps Key<br>YouTube Key<br>        │<br>        │ Restricted only to<br>        │ required APIs<br>        ▼<br><br>PROJECT B<br>AI Workloads<br>Gemini API<br>Dedicated credential<br>Dedicated monitoring<br>Dedicated budget<br>Dedicated spend cap</pre><p>Project separation is not always required.</p><p>But separating workloads can reduce the blast radius.</p><p>If a public Maps API key is compromised, that should not automatically expose your generative AI budget.</p><h3>What We Changed</h3><p>After this incident, the approach to API key management changed.</p><p>The goal was no longer simply:</p><blockquote><em>“Does the application work?”</em></blockquote><p>The new question became:</p><blockquote><em>“What happens if this credential is stolen?”</em></blockquote><p>That led to a much stronger checklist.</p><h3>1. Audit Every API Key</h3><p>For every key:</p><pre>Owner?<br>Purpose?<br>Application?<br>Allowed APIs?<br>Restriction?<br>Last used?<br>Still required?</pre><p>If nobody can explain why a key exists:</p><p><strong>Delete it.</strong></p><h3>2. Remove Unrestricted Keys</h3><p>Unrestricted keys should be treated as technical debt.</p><p>Especially old keys.</p><p>Especially keys that were created before current security practices were established.</p><p>Google’s current Gemini API documentation is also moving toward stronger key controls: it states that unrestricted standard keys are rejected for Gemini API requests, and new AI Studio keys are created as auth keys by default. The documentation also describes additional migration and restriction requirements for standard keys.</p><p>That is an important improvement, but organizations should not wait for platform defaults to protect every historical credential.</p><h3>3. Use Dedicated Credentials</h3><p>Avoid this:</p><pre>ONE KEY<br>   │<br>   ├── Maps<br>   ├── YouTube<br>   ├── Firebase<br>   └── AI</pre><p>Prefer:</p><pre>Maps Key<br>    └── Maps APIs only<br>YouTube Key<br>    └── YouTube APIs only<br>Gemini Credential<br>    └── Gemini only</pre><p>Smaller permissions mean a smaller blast radius.</p><h3>4. Enable Financial Guardrails</h3><p>For Gemini workloads, configure multiple layers:</p><pre>                  GEMINI API<br>                        │<br>                        ▼<br>              ┌─────────────────┐<br>              │ Rate Limits     │<br>              └────────┬────────┘<br>                       │<br>                       ▼<br>              ┌─────────────────┐<br>              │ Budget Alerts   │<br>              │ 50% / 80% / ... │<br>              └────────┬────────┘<br>                       │<br>                       ▼<br>              ┌─────────────────┐<br>              │ Cost Anomaly    │<br>              │ Detection       │<br>              └────────┬────────┘<br>                       │<br>                       ▼<br>              ┌─────────────────┐<br>              │ Spend Cap       │<br>              │ Financial Stop  │<br>              └─────────────────┘</pre><p>Google Cloud now supports spend cap budgets for Gemini API in eligible projects and billing configurations, providing an additional safety mechanism beyond traditional budget alerts.</p><h3>The Bigger Lesson: AI Changes the Cost of Credential Exposure</h3><p>Before generative AI, an exposed API key might create:</p><ul><li>Unexpected Maps API usage</li><li>YouTube quota abuse</li><li>API quota exhaustion</li></ul><p>Those were already serious problems.</p><p>But generative AI changes the financial equation.</p><p>A compromised credential can now be used to consume:</p><ul><li>Large language model inference</li><li>Large context windows</li><li>High-volume automated prompts</li><li>Expensive model workloads</li></ul><p>The attacker’s infrastructure cost is effectively close to zero.</p><p>The victim pays.</p><p>This changes the threat model.</p><pre>#Traditional Security Incident<br><br>Credential Leak<br>      │<br>      ▼<br>Unauthorized Access<br>      │<br>      ▼<br>Security Impact<br><br>Generative AI Incident<br>Credential Leak<br>      │<br>      ▼<br>Unauthorized API Usage<br>      │<br>      ▼<br>High-Volume AI Consumption<br>      │<br>      ▼<br>💸 Financial Impact<br>      │<br>      ▼<br>Security + FinOps Incident</pre><p>Security teams need to think about billing exposure.</p><p>FinOps teams need to think about credential exposure.</p><p>And cloud engineers need to design for both.</p><h3>Final Thoughts</h3><p>The most important lesson from this incident was surprisingly simple:</p><blockquote><strong><em>An API key should never be trusted just because it was created for a different API.</em></strong></blockquote><p>Cloud projects change.</p><p>New APIs are enabled.</p><p>Old credentials survive.</p><p>Applications are migrated.</p><p>Repositories are forgotten.</p><p>And technical debt quietly accumulates.</p><p>A key that was created years ago for Google Maps might not seem related to Gemini today.</p><p>Until suddenly, it is.</p><p>In our case, an unrestricted and compromised API key became part of a chain of events that resulted in approximately <strong>Rp6 billion of unexpected Gemini API usage</strong>.</p><p>There was no single catastrophic failure.</p><p>Instead, it was a combination of small gaps:</p><pre>Legacy Key<br>     +<br>No Restrictions<br>     +<br>Credential Exposure<br>     +<br>Gemini API Enabled<br>     +<br>No Financial Hard Stop<br>     =<br>Multi-Billion Rupiah Incident</pre><p>The good news is that every part of that chain can be improved.</p><p>Restrict your API keys.</p><p>Separate workloads where appropriate.</p><p>Rotate exposed credentials.</p><p>Monitor AI-specific costs.</p><p>Use anomaly detection.</p><p>Set budgets.</p><p>And where available, configure spend caps.</p><p>Because in the age of generative AI:</p><blockquote><strong><em>Your API key is no longer just a key to an API.</em></strong></blockquote><blockquote><strong><em>It may also be a key to your cloud budget.</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c830199e96d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When Every API Request Started Returning 429: Debugging SpikeArrest and Quota in Google Cloud…]]></title>
            <link>https://medium.com/@randiadhityassaputra/when-every-api-request-started-returning-429-debugging-spikearrest-and-quota-in-google-cloud-b4528215e8d4?source=rss-902c700e3176------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4528215e8d4</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[rate-limit]]></category>
            <category><![CDATA[misconfiguration]]></category>
            <category><![CDATA[apigee]]></category>
            <dc:creator><![CDATA[Randi Adhityas Saputra]]></dc:creator>
            <pubDate>Sun, 23 Aug 2026 03:08:33 GMT</pubDate>
            <atom:updated>2026-08-23T09:34:50.022Z</atom:updated>
            <content:encoded><![CDATA[<h3>When Every API Request Started Returning 429: Debugging SpikeArrest and Quota in Google Cloud Apigee</h3><p>When I started managing an existing client environment, one of the systems I had to maintain was an API running behind <strong>Google Cloud Apigee</strong>.</p><p>At first, everything looked normal.</p><p>The API proxy had security policies, rate limiting, and quota controls. On paper, the configuration looked reasonable.</p><p>Then the problem appeared.</p><p>Almost every request started returning errors such as:</p><pre>429 Too Many Requests</pre><p>And in some scenarios:</p><pre>403 Forbidden</pre><p>At first, the obvious assumption was that the client was simply exceeding the configured rate limit.</p><p>But after investigating the Apigee policies, the actual problem was more fundamental:</p><blockquote><em>Apigee was trying to apply rate limits based on an identifier that was not consistently available for incoming requests.</em></blockquote><p>The policies were configured to identify callers using:</p><pre>&lt;Identifier ref=&quot;developer.app.name&quot;/&gt;</pre><p>The problem was that not every request had a resolved developer.app.name.</p><p>Without understanding how Apigee identifies a caller, rate limiting can behave very differently from what we expect.</p><p>This article explains what I learned while debugging this issue, including:</p><ul><li>The difference between <strong>SpikeArrest</strong> and <strong>Quota</strong></li><li>Why the Identifier is important</li><li>Why missing or incorrect identifiers can cause unexpected rate limiting</li><li>When to use developer.app.name</li><li>When using client IP might make sense</li><li>How I approached changing the identifier for this client environment</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*WHRjgmdA5RyiPqbCKwVnAw.png" /></figure><h3>The Original Configuration</h3><p>The API proxy contained two rate-limiting policies.</p><p>The first was <strong>SpikeArrest</strong>.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;SpikeArrest continueOnError=&quot;false&quot;<br>             enabled=&quot;true&quot;<br>             name=&quot;SA-SpikeArrest5ps&quot;&gt;<br>  &lt;DisplayName&gt;SA-SpikeArrest5ps&lt;/DisplayName&gt;<br>  &lt;Properties/&gt;<br>  &lt;Identifier ref=&quot;developer.app.name&quot;/&gt;<br>  &lt;UseEffectiveCount&gt;true&lt;/UseEffectiveCount&gt;<br>  &lt;MessageWeight ref=&quot;request.header.weight&quot;/&gt;<br>  &lt;Rate ref=&quot;app.developer_spike_rate&quot;&gt;25ps&lt;/Rate&gt;<br>&lt;/SpikeArrest&gt;</pre><p>The second was <strong>Quota</strong>.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;Quota continueOnError=&quot;false&quot;<br>       enabled=&quot;true&quot;<br>       name=&quot;Q-Quota30ReqsIn1Minute&quot;&gt;<br>  &lt;DisplayName&gt;Q-Quota30ReqsIn1Minute&lt;/DisplayName&gt;<br>  &lt;Properties/&gt;<br>  &lt;Identifier ref=&quot;developer.app.name&quot;/&gt;<br>  &lt;Allow count=&quot;150&quot;<br>         countRef=&quot;app.developer_quota_limit&quot;/&gt;<br>  &lt;Interval ref=&quot;request.header.quota_count&quot;&gt;1&lt;/Interval&gt;<br>  &lt;Distributed&gt;true&lt;/Distributed&gt;<br>  &lt;Synchronous&gt;true&lt;/Synchronous&gt;<br>  &lt;TimeUnit ref=&quot;request.header.quota_timeout&quot;&gt;minute&lt;/TimeUnit&gt;<br>&lt;/Quota&gt;</pre><p>Both policies had something important in common:</p><pre>&lt;Identifier ref=&quot;developer.app.name&quot;/&gt;</pre><p>That line turned out to be the key to understanding the problem.</p><h3>First, What Is an Identifier in Apigee?</h3><p>Both SpikeArrest and Quota can maintain limits for a specific caller.</p><p>The Identifier determines <strong>who Apigee considers to be the consumer of the limit</strong>.</p><p>For example:</p><pre>&lt;Identifier ref=&quot;developer.app.name&quot;/&gt;</pre><p>Conceptually means:</p><pre>Developer App A<br>    └── Rate limit bucket A<br><br>Developer App B<br>    └── Rate limit bucket B<br><br>Developer App C<br>    └── Rate limit bucket C</pre><p>Each application gets its own counter.</p><p>Another common option is:</p><pre>&lt;Identifier ref=&quot;client_id&quot;/&gt;</pre><p>which usually works well when the API is using API keys or OAuth.</p><p>Google’s Apigee documentation describes Identifier as the value used to create separate counters or buckets based on a flow variable. A commonly used value is client_id, especially when API key or OAuth authentication is part of the request flow.</p><p>The important lesson is:</p><blockquote><em>The identifier must actually exist when the policy executes.</em></blockquote><h3>The Problem: developer.app.name Was Not Always Available</h3><p>In this environment, the policies expected:</p><pre>developer.app.name</pre><p>to identify the caller.</p><p>But that value is normally associated with an Apigee developer application and is typically available when the request has gone through the appropriate application or credential validation flow.</p><p>For example, a typical architecture might look like this:</p><pre>         Client<br>           │<br>           │ API Key / OAuth Token<br>           ▼<br>┌───────────────────────┐<br>│ VerifyAPIKey          │<br>│ or OAuth Validation   │<br>└───────────┬───────────┘<br>            │<br>            │ Resolve client/app context<br>            ▼<br>┌───────────────────────┐<br>│ developer.app.name    │<br>└───────────┬───────────┘<br>            │<br>            ▼<br>   SpikeArrest / Quota</pre><p>If the request does not provide the expected credential, or the authentication policy does not execute before SpikeArrest and Quota, then the identifier may not resolve as expected.</p><p>That creates a serious design question:</p><blockquote><em>What exactly is Apigee using as the identity of the caller when the policy executes?</em></blockquote><p>This was the area I needed to investigate.</p><p>The rate-limiting configuration itself was not necessarily wrong. The problem was that the <strong>identity model used by the rate limiter did not consistently match the actual incoming requests</strong>.</p><h3>Why the API Was Returning 429</h3><p>A 429 Too Many Requests response generally means the configured rate or quota limit has been exceeded.</p><p>However, debugging a 429 is not only about checking this:</p><pre>&lt;Rate&gt;25ps&lt;/Rate&gt;</pre><p>or this:</p><pre>&lt;Allow count=&quot;150&quot;/&gt;</pre><p>You also need to ask:</p><pre>Who is being counted?</pre><p>For example, imagine the intended architecture is:</p><pre>App A → 25 requests/sec<br>App B → 25 requests/sec<br>App C → 25 requests/sec</pre><p>With a proper identifier:</p><pre>                ┌──────────────┐<br>App A ─────────▶│ Bucket: App A│<br>                │    25/sec    │<br>                └──────────────┘<br><br>                 ┌──────────────┐<br>App B ─────────▶│ Bucket: App B│<br>                │    25/sec    │<br>                └──────────────┘<br>                ┌──────────────┐<br>App C ─────────▶│ Bucket: App C│<br>                │    25/sec    │<br>                └──────────────┘</pre><p>Each application has its own limit.</p><p>But if the identifier is not correctly resolved, the behavior may no longer match the intended per-application design.</p><p>This is why rate-limit troubleshooting should not start only with:</p><blockquote><em>“Should we increase the limit?”</em></blockquote><p>It should start with:</p><blockquote><em>“What identifier is this policy actually using for this request?”</em></blockquote><h3>SpikeArrest vs Quota: They Solve Different Problems</h3><p>One of the most important things I learned while managing this Apigee configuration is that <strong>SpikeArrest and Quota are not interchangeable</strong>.</p><p>They both limit requests, but they protect against different problems.</p><h3>SpikeArrest: Protect Against Sudden Traffic Spikes</h3><p>SpikeArrest is designed to control sudden bursts of traffic.</p><p>For example:</p><pre>&lt;Rate&gt;25ps&lt;/Rate&gt;</pre><p>means the API should enforce a configured request rate of 25 requests per second.</p><p>Conceptually:</p><pre>            Incoming Traffic<br>                     │<br>                     ▼<br>        ┌────────────────────────┐<br>        │      SpikeArrest       │<br>        │                        │<br>        │        25 req/s        │<br>        └────────────┬───────────┘<br>                     │<br>                     ▼<br>                Backend API</pre><p>The purpose is to prevent something like this:</p><pre>Normal traffic<br>██████████<br>Sudden spike<br>████████████████████████████████████████████</pre><p>from overwhelming the backend.</p><p>Google recommends using SpikeArrest for operational protection against sudden API traffic spikes, while Quota is better suited for enforcing business contracts or SLAs.</p><h3>Example</h3><pre>&lt;SpikeArrest name=&quot;SA-25ps&quot;&gt;<br>    &lt;Identifier ref=&quot;client_id&quot;/&gt;<br>    &lt;Rate&gt;25ps&lt;/Rate&gt;<br>    &lt;UseEffectiveCount&gt;true&lt;/UseEffectiveCount&gt;<br>&lt;/SpikeArrest&gt;</pre><p>This means the rate can be applied separately based on the selected identifier.</p><p>Apigee supports rate values in requests per second (ps) or requests per minute (pm).</p><h3>Quota: Control Total API Consumption</h3><p>Quota is different.</p><p>Instead of controlling a sudden spike, Quota controls how much an API consumer can use the API during a larger period.</p><p>For example:</p><pre>&lt;Allow count=&quot;150&quot;/&gt;<br>&lt;Interval&gt;1&lt;/Interval&gt;<br>&lt;TimeUnit&gt;minute&lt;/TimeUnit&gt;</pre><p>This represents:</p><pre>150 requests<br>within<br>1 minute</pre><p>Conceptually:</p><pre>              Client<br>                │<br>                ▼<br>      ┌───────────────────┐<br>      │       Quota       │<br>      │                   │<br>      │  150 requests     │<br>      │    per minute     │<br>      └─────────┬─────────┘<br>                │<br>                ▼<br>            Backend</pre><p>After the limit is reached:</p><pre>Request 1    ✓<br>Request 2    ✓<br>Request 3    ✓<br>...<br>Request 150  ✓<br>Request 151  ✗ 429</pre><p>Quota maintains request counters over a defined interval and rejects subsequent calls once the configured limit has been reached until the quota window resets.</p><h3>A Simple Way to Remember the Difference</h3><p>I now think about them like this:</p><p>PolicyMain PurposeExample<strong>SpikeArrest</strong>Protect backend from sudden burstsMaximum 25 requests/second<strong>Quota</strong>Control total API consumptionMaximum 150 requests/minute<strong>SpikeArrest</strong>Operational protection”Don’t overload my backend right now”<strong>Quota</strong>Business/API consumption control”This consumer can only use this many requests”</p><p>A simple architecture could be:</p><pre>              Client<br>                  │<br>                  ▼<br>        ┌─────────────────────┐<br>        │    Authentication   │<br>        │ Verify API Key/OAuth│<br>        └──────────┬──────────┘<br>                   │<br>                   ▼<br>        ┌─────────────────────┐<br>        │    SpikeArrest      │<br>        │     25 req/sec      │<br>        └──────────┬──────────┘<br>                   │<br>                   ▼<br>        ┌─────────────────────┐<br>        │       Quota         │<br>        │    150 req/min      │<br>        └──────────┬──────────┘<br>                   │<br>                   ▼<br>               Backend</pre><p>This gives us two layers of protection.</p><h3>Why developer.app.name Was Not the Right Identifier for Every Request</h3><p>The existing configuration used:</p><pre>&lt;Identifier ref=&quot;developer.app.name&quot;/&gt;</pre><p>This approach makes sense if every caller is a properly registered Apigee developer application and the request flow reliably resolves that application context before the rate-limiting policies execute.</p><p>For example:</p><pre>Client<br>   │<br>   │ API Key<br>   ▼<br>VerifyAPIKey<br>   │<br>   ▼<br>developer.app.name<br>   │<br>   ├── SpikeArrest<br>   │<br>   └── Quota</pre><p>In that scenario, developer.app.name is a logical identifier because every application can have its own rate-limit bucket.</p><p>However, the client environment I was managing did not consistently follow that model for every incoming request.</p><p>Some requests did not have the expected application identity available.</p><p>That meant the rate-limiting policy was relying on a value that could not always represent the actual caller.</p><p>So instead of asking:</p><blockquote><em>“Should I increase the limit from 25ps to 50ps?”</em></blockquote><p>The more important question became:</p><blockquote><em>“What should represent a unique client in this API?”</em></blockquote><h3>My First Approach: Use the Client IP Address</h3><p>Since the API did not consistently have an application identifier available for every request, one possible approach was to identify clients using their source IP.</p><p>Conceptually:</p><pre>Client A<br>IP: 10.10.10.1<br>      │<br>      ▼<br>Bucket: 10.10.10.1<br>25 req/sec<br></pre><pre>Client B<br>IP: 10.10.10.2<br>      │<br>      ▼<br>Bucket: 10.10.10.2<br>25 req/sec</pre><p>The policy could conceptually use a request-derived client IP variable as the identifier:</p><pre>&lt;Identifier ref=&quot;client.ip&quot;/&gt;</pre><p>Then the SpikeArrest configuration would become something like:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;SpikeArrest continueOnError=&quot;false&quot;<br>             enabled=&quot;true&quot;<br>             name=&quot;SA-SpikeArrest5ps&quot;&gt;<br>    &lt;DisplayName&gt;SA-SpikeArrest5ps&lt;/DisplayName&gt;<br>    &lt;Properties/&gt;<br>    &lt;Identifier ref=&quot;client.ip&quot;/&gt;<br>    &lt;UseEffectiveCount&gt;true&lt;/UseEffectiveCount&gt;<br>    &lt;MessageWeight ref=&quot;request.header.weight&quot;/&gt;<br>    &lt;Rate ref=&quot;app.developer_spike_rate&quot;&gt;25ps&lt;/Rate&gt;<br>&lt;/SpikeArrest&gt;<br><br></pre><p>And the Quota policy:</p><pre>Before<br><br>developer.app.name<br>        │<br>        ▼<br>Rate Limit Bucket</pre><p>becomes:</p><pre>    Client IP<br>        │<br>        ▼<br>Rate Limit Bucket</pre><h3>But Client IP Is Not Always the Perfect Identifier</h3><p>Using client IP is useful when there is no API key, OAuth identity, or developer application context.</p><p>However, it has an important limitation.</p><p>Consider this architecture:</p><pre>                ┌───────────────┐<br>Client A ───────▶               │<br>                │     NAT /      │<br>Client B ───────▶   Load Balancer├──────▶ Apigee<br>                │                │<br>Client C ───────▶               │<br>                └───────────────┘<br>                         │<br>                         │<br>                    One Public IP</pre><p>From Apigee’s perspective, multiple users may appear to come from the same IP.</p><p>That means:</p><pre>Client A<br>Client B<br>Client C<br>     │<br>     ▼<br>Same IP Address<br>     │<br>     ▼<br>Same Rate Limit Bucket</pre><p>One noisy client could therefore consume the shared limit.</p><p>There is also the reverse problem: a single client using multiple IP addresses could effectively receive multiple buckets.</p><p>So my rule of thumb is:</p><pre>Best Identifier<br>      │<br>      ▼<br>Authenticated API Consumer<br>(API Key / OAuth / Developer App)<br>      │<br>      ▼<br>Client ID<br>      │<br>      ▼<br>Client IP<br>      │<br>      ▼<br>Global Limit</pre><p>Client IP is often a practical fallback, but it is not as strong as a true authenticated application identity.</p><p>Also, if Apigee is behind another proxy or load balancer, it is important to verify which flow variable contains the actual client IP rather than blindly trusting a client-supplied header.</p><h3>The Better Long-Term Approach: Use the Developer Application Name</h3><p>After investigating the existing configuration, another possible direction is to properly restore the intended application identity model.</p><p>Instead of removing:</p><pre>&lt;Identifier ref=&quot;developer.app.name&quot;/&gt;</pre><p>the better long-term solution may be to ensure that the request is associated with an Apigee developer application.</p><p>The flow would look like:</p><pre>                    Request<br>                       │<br>                       ▼<br>             ┌───────────────────┐<br>             │ Verify API Key    │<br>             │ or OAuth Token    │<br>             └─────────┬─────────┘<br>                       │<br>                       ▼<br>             ┌───────────────────┐<br>             │ Resolve App       │<br>             │ Identity          │<br>             │                   │<br>             │ developer.app.name│<br>             └─────────┬─────────┘<br>                       │<br>             ┌─────────┴─────────┐<br>             ▼                   ▼<br>         SpikeArrest            Quota</pre><p>Then each application gets an independent rate limit.</p><p>For example:</p><pre>Application A<br>25 req/sec<br>150 req/min<br><br>Application B<br>25 req/sec<br>150 req/min<br><br>Application C<br>25 req/sec<br>150 req/min</pre><p>This is usually much closer to the original purpose of Apigee’s developer apps and API products.</p><p>Apigee’s Quota documentation specifically notes that client_id is commonly used as an identifier when API key or OAuth authorization is enabled.</p><h3>Understanding the Dynamic Configuration in the Existing Policy</h3><p>Another interesting part of the original configuration was this:</p><pre>&lt;Rate ref=&quot;app.developer_spike_rate&quot;&gt;25ps&lt;/Rate&gt;</pre><p>and:</p><pre>&lt;Allow count=&quot;150&quot;<br>       countRef=&quot;app.developer_quota_limit&quot;/&gt;</pre><p>These policies support both a default value and a dynamically resolved value.</p><p>For SpikeArrest:</p><pre>&lt;Rate ref=&quot;app.developer_spike_rate&quot;&gt;25ps&lt;/Rate&gt;</pre><p>means:</p><pre>If app.developer_spike_rate exists<br>    ↓<br>Use that value</pre><pre>Otherwise<br>    ↓<br>Use 25ps</pre><p>For Quota:</p><pre>&lt;Allow count=&quot;150&quot;<br>       countRef=&quot;app.developer_quota_limit&quot;/&gt;</pre><p>means the same general idea:</p><pre>Dynamic configuration available<br>        │<br>        ▼<br>Use application-specific limit</pre><pre>Otherwise<br>        │<br>        ▼<br>Use default: 150</pre><p>This can be useful for different service tiers.</p><p>For example:</p><pre>Free Tier<br>─────────────<br>25 req/sec<br>150 req/min<br></pre><pre>Premium Tier<br>─────────────<br>100 req/sec<br>10,000 req/min</pre><p>But again, dynamic limits only make sense if Apigee can correctly identify the application or client.</p><h3>Why Distributed and Synchronous Matter for Quota</h3><p>The original Quota policy contains:</p><pre>&lt;Distributed&gt;true&lt;/Distributed&gt;<br>&lt;Synchronous&gt;true&lt;/Synchronous&gt;</pre><p>This is important in a distributed Apigee environment.</p><p>Imagine multiple message processors handling requests.</p><p>Without a shared quota counter:</p><pre>                  ┌────────────────┐<br>Request ────────▶ Message Processor 1<br>                  │ Counter: 100   │<br>                  └────────────────┘</pre><pre>                ┌────────────────┐<br>Request ────────▶ Message Processor 2<br>                │ Counter: 100   │<br>                └────────────────┘</pre><p>A quota intended to allow 100 requests could potentially be exceeded across multiple processors.</p><p>With:</p><pre>&lt;Distributed&gt;true&lt;/Distributed&gt;</pre><p>Apigee uses a shared distributed counter across processors. Google recommends distributed quota when multiple message processors handle API traffic.</p><p>With:</p><pre>&lt;Synchronous&gt;true&lt;/Synchronous&gt;</pre><p>the quota counter is updated synchronously with request processing.</p><p>That gives stricter quota enforcement, but there is a trade-off: synchronous counter updates can affect performance and throughput.</p><p>So this configuration:</p><pre>&lt;Distributed&gt;true&lt;/Distributed&gt;<br>&lt;Synchronous&gt;true&lt;/Synchronous&gt;</pre><p>makes sense when the requirement is:</p><blockquote><em>Do not allow requests to exceed the quota, even slightly.</em></blockquote><p>But if extremely high throughput is more important and small quota overruns are acceptable, asynchronous behavior may be worth considering.</p><h3>A Troubleshooting Workflow I Would Recommend</h3><p>After this experience, I would troubleshoot Apigee 429 responses in this order.</p><h3>Step 1: Identify Which Policy Is Returning the Error</h3><p>First determine whether the response comes from:</p><pre>SpikeArrest</pre><p>or:</p><pre>Quota</pre><p>Both can result in rejected requests, but the investigation is different.</p><h3>Step 2: Inspect the Identifier</h3><p>Check:</p><pre>&lt;Identifier ref=&quot;...&quot;/&gt;</pre><p>Then ask:</p><pre>Does this flow variable exist?<br>Does it exist before this policy executes?<br>Does it uniquely represent the caller?</pre><p>For example:</p><pre>developer.app.name</pre><p>requires a valid application context.</p><pre>client_id</pre><p>requires the appropriate client credential flow.</p><pre>client.ip</pre><p>depends on the network and proxy architecture.</p><h3>Step 3: Check the Policy Order</h3><p>The flow should generally resolve identity before applying a per-client limit.</p><p>For example:</p><pre>BAD ORDER</pre><pre>SpikeArrest<br>     │<br>     ▼<br>   Quota<br>     │<br>     ▼<br>VerifyAPIKey</pre><p>The identifier may not yet be available.</p><p>A better order is:</p><pre>VerifyAPIKey<br>     │<br>     ▼<br>Resolve Client Identity<br>     │<br>     ▼<br>SpikeArrest<br>     │<br>     ▼<br>Quota<br>     │<br>     ▼<br>Backend</pre><h3>Step 4: Check Dynamic Variables</h3><p>The original configuration uses dynamic references:</p><pre>app.developer_spike_rate</pre><p>and:</p><pre>app.developer_quota_limit</pre><p>Also:</p><pre>request.header.quota_count</pre><p>and:</p><pre>request.header.quota_timeout</pre><p>These need to be validated carefully.</p><p>The key question is:</p><pre>Where are these variables populated?</pre><p>If the values come from API products, application configuration, KVMs, headers, or earlier policies, make sure they are available at runtime.</p><p>For Interval and TimeUnit, Apigee gives the referenced variable precedence when it resolves; otherwise the literal fallback value can be used.</p><h3>A Simpler Baseline Configuration</h3><p>For troubleshooting, I prefer to temporarily remove unnecessary dynamic behavior and start with a predictable baseline.</p><p>For example:</p><h3>SpikeArrest</h3><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;SpikeArrest continueOnError=&quot;false&quot;<br>             enabled=&quot;true&quot;<br>             name=&quot;SA-ClientRateLimit&quot;&gt;<br>    &lt;DisplayName&gt;SA-ClientRateLimit&lt;/DisplayName&gt;<br>    &lt;Properties/&gt;<br>    &lt;Identifier ref=&quot;client.ip&quot;/&gt;<br>    &lt;Rate&gt;25ps&lt;/Rate&gt;<br>    &lt;UseEffectiveCount&gt;true&lt;/UseEffectiveCount&gt;<br>&lt;/SpikeArrest&gt;</pre><h3>Quota</h3><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;<br>&lt;Quota continueOnError=&quot;false&quot;<br>       enabled=&quot;true&quot;<br>       name=&quot;Q-ClientQuota&quot;&gt;<br>    &lt;DisplayName&gt;Q-ClientQuota&lt;/DisplayName&gt;<br>    &lt;Properties/&gt;<br>    &lt;Identifier ref=&quot;client.ip&quot;/&gt;<br>    &lt;Allow count=&quot;150&quot;/&gt;<br>    &lt;Interval&gt;1&lt;/Interval&gt;<br>    &lt;TimeUnit&gt;minute&lt;/TimeUnit&gt;<br>    &lt;Distributed&gt;true&lt;/Distributed&gt;<br>    &lt;Synchronous&gt;true&lt;/Synchronous&gt;<br>&lt;/Quota&gt;</pre><p>Once this works predictably, dynamic application-specific configuration can be added again.</p><h3>The Architecture I Would Prefer</h3><p>For a production API platform, my preferred design would be:</p><pre>                        CLIENT<br>                          │<br>                          ▼<br>                 ┌────────────────────┐<br>                 │ Authentication     │<br>                 │ API Key / OAuth    │<br>                 └─────────┬──────────┘<br>                           │<br>                           ▼<br>                 ┌────────────────────┐<br>                 │ Resolve Identity   │<br>                 │                    │<br>                 │ client_id          │<br>                 │ developer.app.name │<br>                 └─────────┬──────────┘<br>                           │<br>                           ▼<br>                 ┌────────────────────┐<br>                 │ SpikeArrest        │<br>                 │                    │<br>                 │ 25 requests/sec    │<br>                 └─────────┬──────────┘<br>                           │<br>                           ▼<br>                 ┌────────────────────┐<br>                 │ Quota              │<br>                 │                    │<br>                 │ 150 requests/min   │<br>                 └─────────┬──────────┘<br>                           │<br>                           ▼<br>                 ┌────────────────────┐<br>                 │ Backend Service    │<br>                 └────────────────────┘</pre><p>This provides:</p><ul><li>Authentication</li><li>A reliable client identity</li><li>Protection against sudden traffic spikes</li><li>Control over total API consumption</li><li>The ability to configure different limits for different applications</li></ul><h3>One Important Warning: Don’t Use an Identifier That Changes Every Request</h3><p>When choosing an identifier, it should represent a stable consumer.</p><p>For example:</p><p>Good identifiers</p><pre>client_id<br>developer.app.name<br>developer.id<br>stable client IP</pre><p>Avoid identifiers such as:</p><pre>request ID<br>timestamp<br>random UUID<br>session values that constantly change</pre><p>A high-cardinality identifier can create effectively separate quota buckets for almost every request and undermine quota enforcement. Google explicitly documents this as an Apigee anti-pattern.</p><p>The identifier should answer:</p><blockquote><em>“Which requests belong to the same API consumer?”</em></blockquote><h3>Lessons Learned</h3><p>The biggest lesson from this incident was that rate limiting is not just about numbers.</p><p>You can configure:</p><pre>25 requests per second</pre><p>or:</p><pre>150 requests per minute</pre><p>But those numbers are meaningless until you define:</p><pre>25 requests per second...</pre><pre>for whom?</pre><p>The answer is determined by the identifier.</p><p>My debugging process changed from:</p><pre>429 response<br>     │<br>     ▼<br>Increase rate limit?</pre><p>to:</p><pre>429 response<br>     │<br>     ▼<br>Which policy rejected the request?<br>     │<br>     ▼<br>What identifier does it use?<br>     │<br>     ▼<br>Does that identifier exist at runtime?<br>     │<br>     ▼<br>Does it uniquely represent the caller?<br>     │<br>     ▼<br>Then evaluate the configured limit.</pre><p>That was the real fix.</p><h3>Final Thoughts</h3><p>Apigee gives us powerful tools for protecting APIs, but <strong>SpikeArrest and Quota need to be designed around the actual identity of the API consumer</strong>.</p><p>In my case, the unexpected 429 responses led me to investigate the following configuration:</p><pre>&lt;Identifier ref=&quot;developer.app.name&quot;/&gt;</pre><p>The issue was not simply that the rate was too low.</p><p>The more important question was whether Apigee could consistently resolve the identity used by the policy.</p><p>For environments where API consumers are properly registered and authenticated, using a stable application or client identity such as developer.app.name or client_id is generally the cleaner design.</p><p>For environments where that identity is not available, a network-based identifier such as the client IP can be a practical fallback, provided the proxy and NAT architecture are understood.</p><p>The main takeaway is simple:</p><blockquote><strong><em>Before tuning a rate limit, make sure you know exactly who Apigee is counting.</em></strong></blockquote><p>Because in API management, the number is only half of the configuration.</p><p>The identity behind the counter is the other half.</p><h3>References</h3><ul><li><a href="https://docs.cloud.google.com/apigee/docs/api-platform/reference/policies/spike-arrest-policy?authuser=1&amp;utm_source=chatgpt.com">Apigee SpikeArrest policy documentation</a></li><li><a href="https://docs.cloud.google.com/apigee/docs/api-platform/reference/policies/quota-policy?hl=en&amp;utm_source=chatgpt.com">Apigee Quota policy documentation</a></li><li><a href="https://docs.cloud.google.com/apigee/docs/api-platform/antipatterns/high-cardinality-identifiers-quota-policy?utm_source=chatgpt.com">Apigee guidance on high-cardinality quota identifiers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4528215e8d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Merged Two S3 Buckets into One: A Simple Step to Reduce Cloud Technical Debt]]></title>
            <link>https://medium.com/@randiadhityassaputra/i-merged-two-s3-buckets-into-one-a-simple-step-to-reduce-cloud-technical-debt-94c8c7bc4cbe?source=rss-902c700e3176------2</link>
            <guid isPermaLink="false">https://medium.com/p/94c8c7bc4cbe</guid>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Randi Adhityas Saputra]]></dc:creator>
            <pubDate>Sun, 23 Aug 2026 02:44:44 GMT</pubDate>
            <atom:updated>2026-08-23T02:44:44.641Z</atom:updated>
            <content:encoded><![CDATA[<p>When I joined an existing project, I expected my first challenge to be building something new.</p><p>Instead, I spent a lot of time trying to understand what was already there.</p><p>And that is often the reality of working with existing infrastructure.</p><p>Cloud environments have history.</p><p>Resources are created to solve urgent problems. Some are built for experiments. Others are intended to be temporary, but somehow remain in production long after the original reason for creating them has been forgotten.</p><p>Over time, these decisions accumulate.</p><p>We usually call this <strong>technical debt</strong>.</p><p>Most engineers associate technical debt with application code: old libraries, duplicated functions, shortcuts, and fragile architectures.</p><p>But infrastructure has technical debt too.</p><p>Unused resources. Confusing naming. Duplicate configurations. Forgotten dependencies. Temporary architectures that quietly become permanent.</p><p>While reviewing an existing AWS environment, I found a small example of exactly that.</p><p>It was not a major outage.</p><p>It was not a broken production system.</p><p>It was just… more complicated than it needed to be.</p><p>And the solution was surprisingly simple:</p><p><strong>Two S3 buckets became one.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mc5Y6_A8AziVM-arL5XDtw.png" /></figure><h3>The First Thing I Noticed: Too Many Storage Locations</h3><p>During the initial infrastructure review, I found multiple Amazon S3 buckets serving a similar purpose.</p><p>The applications were working.</p><p>Files were uploading successfully.</p><p>Objects could still be retrieved.</p><p>From the application’s perspective, there was no immediate problem.</p><p>But from an infrastructure perspective, something felt wrong.</p><p>The bucket naming and ownership were not immediately clear.</p><p>There were buckets with names like:</p><pre>storage-dev</pre><p>And others that looked like they had been created at different points in the project’s history:</p><pre>upload-storage-v2<br>temporary-storage<br>old-assets<br>random-storage-name</pre><p>Seeing this immediately raised a question:</p><blockquote><em>If the engineer who originally created these resources left tomorrow, would the next engineer understand why each bucket exists?</em></blockquote><p>That question became the starting point for the cleanup.</p><p>Infrastructure should not depend on tribal knowledge.</p><p>If understanding an environment requires asking the person who built it three years ago, the architecture is already carrying unnecessary operational risk.</p><h3>Working Infrastructure Does Not Always Mean Good Infrastructure</h3><p>One of the easiest traps in infrastructure is thinking:</p><blockquote><em>“It is working, so don’t touch it.”</em></blockquote><p>Sometimes that is absolutely the right decision.</p><p>Changing a stable system without a clear reason can introduce more risk than value.</p><p>But “working” and “well-designed” are not always the same thing.</p><p>A system can work perfectly while still being unnecessarily difficult to operate.</p><p>Multiple S3 buckets, for example, can introduce additional management overhead.</p><p>Each bucket may eventually need its own:</p><ul><li>IAM permissions</li><li>Bucket policies</li><li>Encryption configuration</li><li>Lifecycle rules</li><li>Monitoring and logging</li><li>Backup or replication policies</li><li>Documentation</li></ul><p>Even if the configuration is simple today, duplication creates more places where configuration can drift tomorrow.</p><p>With two buckets:</p><pre>bucket-a<br>bucket-b</pre><p>there are two storage locations to understand, secure, monitor, and document.</p><p>With a single, clearly defined bucket:</p><pre>main-bucket-storage</pre><p>the architecture becomes easier to reason about.</p><p>The goal was not to reduce the number of resources just for the sake of having fewer resources.</p><p>The goal was to remove complexity that was no longer providing value.</p><h3>The Decision: Consolidate the Storage</h3><p>After reviewing the bucket usage and confirming that the buckets served the same logical purpose, I decided to consolidate them.</p><p>The architecture before the migration looked conceptually like this:</p><pre>┌──────────────────┐<br>│   storage-old    │<br>└──────────────────┘</pre><pre>┌──────────────────┐<br>│   storage-new    │<br>└──────────────────┘</pre><p>The target architecture became:</p><pre>┌──────────────────────────┐<br>│   main-bucket-storage    │<br>│                          │<br>│  Single storage location │<br>└──────────────────────────┘</pre><p>One primary bucket.</p><p>One destination.</p><p>One place to manage.</p><p>But before doing that, there was an important question.</p><h3>Why Not Just Keep Both Buckets?</h3><p>Keeping multiple buckets is not automatically bad architecture.</p><p>There are plenty of valid reasons to separate storage.</p><p>For example:</p><ul><li>Different security requirements</li><li>Different teams or ownership boundaries</li><li>Different data classifications</li><li>Different AWS accounts</li><li>Different lifecycle or retention policies</li><li>Isolation between environments</li><li>Compliance requirements</li></ul><p>In those cases, separating buckets can actually make the architecture safer and easier to manage.</p><p>But that was not the situation here.</p><p>These buckets were effectively being used for the same purpose.</p><p>They had become separate because of historical decisions rather than architectural requirements.</p><p>Keeping them separate created additional operational work without providing meaningful benefits.</p><p>So consolidation made sense.</p><h3>The Migration Strategy: Two Buckets Into One</h3><p>The migration itself was conceptually simple.</p><p>There were two source buckets:</p><pre>Source Bucket A<br>        │<br>        │<br>        ▼<br>┌──────────────────────────┐<br>│   main-bucket-storage    │<br>└──────────────────────────┘<br></pre><pre>Source Bucket B<br>        │<br>        │<br>        ▼<br>┌──────────────────────────┐<br>│   main-bucket-storage    │<br>└──────────────────────────┘</pre><p>One important detail is that the migration process needed to run <strong>twice</strong>.</p><p>Why?</p><p>Because there is no S3 command that simply says:</p><pre>merge bucket-a + bucket-b</pre><p>Instead, each source bucket needs to be synchronized independently into the destination.</p><p>Conceptually:</p><pre>aws s3 sync bucket-a → destination</pre><p>Then:</p><pre>aws s3 sync bucket-b → destination</pre><p>The result is a single destination bucket containing the data from both sources.</p><p>Of course, this also means you need to consider one important migration risk:</p><p><strong>What happens if both source buckets contain objects with the same key?</strong></p><p>That should be reviewed before migration.</p><p>If both buckets contain:</p><pre>images/logo.png</pre><p>then the migration order can determine which version ends up in the destination.</p><p>This is why understanding the data structure before running the migration is just as important as the migration command itself.</p><h3>Why I Chose aws s3 sync</h3><p>There are several ways to migrate S3 data.</p><p>For example:</p><ul><li>Download everything to a server and upload it again</li><li>Build a custom migration application</li><li>Use AWS DataSync</li><li>Use S3 Batch Operations</li><li>Use AWS CLI</li></ul><p>For this migration, I chose:</p><pre>aws s3 sync</pre><p>It was the right balance between simplicity, control, and operational visibility.</p><h3>1. It Is Incremental</h3><p>The command does not blindly copy every object again.</p><p>For example:</p><p>Source bucket:</p><pre>old-bucket</pre><pre>image-1.png<br>image-2.png<br>image-3.png</pre><p>Destination bucket:</p><pre>main-bucket-storage</pre><pre>image-1.png</pre><p>Running:</p><pre>aws s3 sync \<br>  s3://old-bucket \<br>  s3://main-bucket-storage</pre><p>will only transfer the objects that need to be synchronized.</p><p>Conceptually:</p><pre>image-1.png  → already exists / unchanged<br>image-2.png  → copied<br>image-3.png  → copied</pre><p>This makes repeated execution much easier.</p><h3>2. It Is Safe to Run Again</h3><p>Large migrations can take hours.</p><p>And real infrastructure does not always behave perfectly.</p><p>The migration process might be interrupted because of:</p><ul><li>A network issue</li><li>A server restart</li><li>An SSH session disconnect</li><li>A process failure</li></ul><p>With aws s3 sync, I can run the synchronization again.</p><p>The command compares the source and destination and continues synchronizing the differences.</p><p>That makes the migration process much more forgiving than a custom one-time copy process.</p><h3>3. It Is Easy for the Next Engineer to Understand</h3><p>This was one of the biggest reasons I chose it.</p><p>A future engineer can look at:</p><pre>aws s3 sync source destination</pre><p>and immediately understand what happened.</p><p>There is very little hidden logic.</p><p>In infrastructure, boring and understandable tools are often better than clever and complicated ones.</p><h3>Building a Small Migration Wrapper</h3><p>Running a single command manually would work.</p><p>But for a real migration, I wanted better visibility.</p><p>I wanted the process to provide:</p><ul><li>Background execution</li><li>Timestamped logs</li><li>Success records</li><li>Failure records</li><li>Basic audit history</li></ul><p>So I created a small wrapper around aws s3 sync.</p><h3>s3-migrate.sh</h3><pre>#!/usr/bin/env bash<br>set -u<br>SOURCE_BUCKET=&quot;${1:?Source bucket is required}&quot;<br>DEST_BUCKET=&quot;${2:?Destination bucket is required}&quot;<br>TIMESTAMP=$(date +&quot;%Y%m%d-%H%M%S&quot;)<br>LOG_DIR=&quot;./migration-history&quot;<br>mkdir -p &quot;${LOG_DIR}&quot;<br>LOG_FILE=&quot;${LOG_DIR}/${SOURCE_BUCKET}-to-${DEST_BUCKET}-${TIMESTAMP}.log&quot;<br>STATUS_FILE=&quot;${LOG_DIR}/${SOURCE_BUCKET}-to-${DEST_BUCKET}-${TIMESTAMP}.status&quot;<br>echo &quot;================================&quot;<br>echo &quot;S3 Migration Started&quot;<br>echo &quot;================================&quot;<br>echo &quot;Source      : ${SOURCE_BUCKET}&quot;<br>echo &quot;Destination : ${DEST_BUCKET}&quot;<br>echo &quot;Started     : $(date)&quot;<br>echo &quot;Log file    : ${LOG_FILE}&quot;<br>echo &quot;================================&quot;<br>if aws s3 sync \<br>    &quot;s3://${SOURCE_BUCKET}&quot; \<br>    &quot;s3://${DEST_BUCKET}&quot; \<br>    &gt; &quot;${LOG_FILE}&quot; 2&gt;&amp;1<br>then<br>    echo &quot;Migration SUCCESS&quot;<br>    cat &gt; &quot;${STATUS_FILE}&quot; &lt;&lt;EOF<br>STATUS=SUCCESS<br>SOURCE=${SOURCE_BUCKET}<br>DESTINATION=${DEST_BUCKET}<br>STARTED=${TIMESTAMP}<br>FINISHED=$(date)<br>EOF<br>else<br>    EXIT_CODE=$?<br>    echo &quot;Migration FAILED with exit code ${EXIT_CODE}&quot;<br>    cat &gt; &quot;${STATUS_FILE}&quot; &lt;&lt;EOF<br>STATUS=FAILED<br>SOURCE=${SOURCE_BUCKET}<br>DESTINATION=${DEST_BUCKET}<br>STARTED=${TIMESTAMP}<br>FINISHED=$(date)<br>EXIT_CODE=${EXIT_CODE}<br>EOF<br>    exit &quot;${EXIT_CODE}&quot;<br>fi</pre><p>The script is intentionally simple.</p><p>It does not try to become a full migration platform.</p><p>Its job is straightforward:</p><pre>Source bucket<br>      │<br>      ▼<br>aws s3 sync<br>      │<br>      ├── Migration log<br>      │<br>      └── Status record</pre><p>That simplicity is valuable.</p><h3>Running the Migration Twice</h3><p>Because two source buckets are being consolidated into one destination, the script is executed once for each source.</p><h3>Migration 1</h3><p>From:</p><pre>storage-old</pre><p>To:</p><pre>main-bucket-storage</pre><p>Run:</p><pre>nohup ./s3-migrate.sh \<br>  storage-old \<br>  main-bucket-storage \<br>  &gt; /dev/null 2&gt;&amp;1 &amp;</pre><h3>Migration 2</h3><p>From:</p><pre>storage-new</pre><p>To:</p><pre>main-bucket-storage</pre><p>Run:</p><pre>nohup ./s3-migrate.sh \<br>  storage-new \<br>  main-bucket-storage \<br>  &gt; /dev/null 2&gt;&amp;1 &amp;</pre><p>Both migrations can now continue running independently in the background.</p><p>The flow looks like this:</p><pre>                    ┌──────────────────────┐<br>                    │ main-bucket-storage  │<br>                    └──────────▲───────────┘<br>                               │<br>                 ┌─────────────┴─────────────┐<br>                 │                           │<br>                 │                           │<br>        ┌────────┴────────┐        ┌────────┴────────┐<br>        │   storage-old   │        │   storage-new   │<br>        └─────────────────┘        └─────────────────┘<br>            Migration #1               Migration #2</pre><h3>Keeping a Migration History</h3><p>After running the migrations, the directory might look like this:</p><pre>migration-history/</pre><pre>storage-old-to-main-bucket-storage-20260823-010000.log<br>storage-old-to-main-bucket-storage-20260823-010000.status</pre><pre>storage-new-to-main-bucket-storage-20260823-010500.log<br>storage-new-to-main-bucket-storage-20260823-010500.status</pre><p>The status file provides a simple audit trail.</p><p>For example:</p><pre>STATUS=SUCCESS<br>SOURCE=storage-old<br>DESTINATION=main-bucket-storage<br>STARTED=20260823-010000<br>FINISHED=Sun Aug 23 01:45:21 WIB 2026</pre><p>This makes it easier to answer questions later:</p><ul><li>Which bucket was migrated?</li><li>When did the migration run?</li><li>Did it succeed?</li><li>Where are the logs?</li></ul><p>A small amount of operational history can save a lot of investigation time later.</p><h3>Monitoring the Migration</h3><p>Because the migration runs in the background, I can check whether the processes are still running.</p><pre>ps aux | grep s3-migrate</pre><p>To watch the migration logs:</p><pre>tail -f migration-history/*.log</pre><p>For a specific migration:</p><pre>tail -f \<br>migration-history/storage-old-to-main-bucket-storage-*.log</pre><h3>Migration Is Not Finished Until It Is Validated</h3><p>One of the biggest mistakes during infrastructure migration is treating this message:</p><pre>Migration SUCCESS</pre><p>as the end of the work.</p><p>It is not.</p><p>A successful command only means the command completed successfully.</p><p>It does not automatically prove that the application will continue working correctly.</p><p>Validation is a separate step.</p><p>For a basic validation, I checked the object counts.</p><p>Source bucket A:</p><pre>aws s3 ls \<br>  s3://storage-old \<br>  --recursive \<br>  --summarize</pre><p>Source bucket B:</p><pre>aws s3 ls \<br>  s3://storage-new \<br>  --recursive \<br>  --summarize</pre><p>Destination:</p><pre>aws s3 ls \<br>  s3://main-bucket-storage \<br>  --recursive \<br>  --summarize</pre><p>At a minimum, the destination should contain the expected combined dataset.</p><p>But object count alone is not always enough.</p><p>Depending on the migration, you may also need to validate:</p><ul><li>Object prefixes</li><li>Object sizes</li><li>Critical files</li><li>Metadata</li><li>Object tags</li><li>Application read/write access</li><li>IAM permissions</li><li>Bucket policies</li><li>Encryption requirements</li></ul><p>The important principle is simple:</p><blockquote><em>Data migration and application validation are two different things.</em></blockquote><h3>Do Not Delete the Old Buckets Immediately</h3><p>Another important lesson from infrastructure work:</p><p><strong>Migration completion is not the same as migration readiness.</strong></p><p>After the data was copied, deleting the original buckets immediately would have been unnecessary risk.</p><p>A safer process looks like this:</p><pre>Day 0<br>│<br>├── Sync source buckets<br>│<br>├── Validate data<br>│<br>└── Update application configuration<br>       │<br>       ▼<br>Day 1–30<br>│<br>├── Monitor application behavior<br>├── Confirm no hidden dependencies<br>└── Keep source buckets as rollback protection<br>       │<br>       ▼<br>After Validation Period<br>│<br>└── Decommission old buckets</pre><p>The exact timeline depends on the environment and business requirements.</p><p>The important part is having a validation period.</p><p>Old resources should not remain forever.</p><p>But they also should not be deleted simply because one migration command returned exit code 0.</p><h3>The Final Result</h3><p>Before the cleanup:</p><pre>storage-old</pre><pre>storage-new</pre><p>After consolidation:</p><pre>main-bucket-storage</pre><p>Two storage locations became one.</p><p>The data was preserved.</p><p>The architecture became easier to understand.</p><p>And future operational work became simpler.</p><h3>The Bigger Lesson Was Not About S3</h3><p>This migration was technically simple.</p><p>There was no complex distributed system redesign.</p><p>No new Kubernetes cluster.</p><p>No major Terraform refactoring.</p><p>No complicated migration framework.</p><p>It was simply a decision to remove unnecessary infrastructure.</p><p>But small improvements like this compound over time.</p><p>A clearer bucket structure means:</p><ul><li>Less confusion for future engineers</li><li>Fewer places to manage permissions</li><li>Simpler documentation</li><li>Easier auditing</li><li>Less configuration drift</li><li>Lower operational complexity</li></ul><p>Infrastructure maturity is not about having more resources.</p><p>It is about having resources that are intentional and easy to understand.</p><p>A confusing bucket name might not cause an outage today.</p><p>A duplicate resource might not increase costs significantly.</p><p>An old architecture might still work perfectly.</p><p>But eventually, someone will ask:</p><blockquote><em>“Why does this exist?”</em></blockquote><p>And if nobody knows the answer, that is usually a good signal that it is time to investigate.</p><h3>Final Thoughts</h3><p>Cloud environments naturally become more complex over time.</p><p>New projects are added.</p><p>Teams change.</p><p>Engineers leave.</p><p>Requirements evolve.</p><p>Temporary solutions become permanent.</p><p>Part of being a DevOps or Cloud Engineer is not only building new infrastructure.</p><p>It is also understanding what already exists and asking whether every part of that infrastructure still needs to be there.</p><p>Sometimes the best engineering work is not adding another service.</p><p>It is removing one.</p><p>Sometimes the biggest improvement is not a new architecture.</p><p>It is making the existing architecture easier to understand.</p><p>In this case, the improvement was simple:</p><pre>Two buckets.<br>One destination.<br>Less complexity.</pre><p>And sometimes, that is exactly what good infrastructure engineering looks like.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94c8c7bc4cbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Change Azure VM Size — And What You Must Think About First]]></title>
            <link>https://medium.com/@randiadhityassaputra/how-to-change-azure-vm-size-and-what-you-must-think-about-first-31a3df7f115a?source=rss-902c700e3176------2</link>
            <guid isPermaLink="false">https://medium.com/p/31a3df7f115a</guid>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[vm]]></category>
            <category><![CDATA[devops-practice]]></category>
            <category><![CDATA[microsoft-azure]]></category>
            <category><![CDATA[resize]]></category>
            <dc:creator><![CDATA[Randi Adhityas Saputra]]></dc:creator>
            <pubDate>Sun, 11 Jan 2026 05:52:35 GMT</pubDate>
            <atom:updated>2026-01-11T05:52:35.760Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Change Azure VM Size — And What You Must Think About First</h3><p>At some point, every cloud engineer hits this moment.</p><p>Your application feels slow.<br>CPU looks busy.<br>Memory usage is always high.</p><p>And you start thinking:</p><blockquote><em>“Maybe this VM is just too small.”</em></blockquote><p>In Azure, changing a VM size is surprisingly easy.<br>But <strong>doing it safely</strong> — especially in production — requires a bit more thought.</p><p>Let’s walk through <strong>how to change VM size in Azure</strong>, and more importantly, <strong>what you should consider before clicking Resize</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*CeCFAkFpJSwgLbXqQYZtaQ.png" /><figcaption>generated with chatGPT</figcaption></figure><h3>Why We Change VM Size in the First Place</h3><p>Azure VMs come in different sizes for a reason.</p><p>Each size defines:</p><ul><li>number of CPU cores</li><li>amount of memory (RAM)</li><li>max network and disk performance</li></ul><p>If your VM is too small:</p><ul><li>apps become slow</li><li>processes get killed</li><li>users start complaining (the worst metric)</li></ul><p>Scaling up the VM (for example, from Standard_B1s to Standard_B2s) gives your server more resources without changing architecture.</p><p>It’s often the <strong>first and fastest fix</strong>.</p><h3>The Simple Way: Changing VM Size via the Azure Portal</h3><p>From a UI perspective, Azure makes VM resizing feel almost <em>too easy</em>.</p><p>No scripts.<br>No CLI.<br>No complicated steps.</p><p>Everything happens directly in the portal.</p><p>Here’s the usual flow:</p><ol><li>Open the <strong>Azure Portal</strong></li><li>Go to <strong>Virtual Machines</strong></li><li>Select your VM<br> <em>(for example: </em><em>apps-server-vm)</em></li><li>In the left-hand menu, click <strong>Size</strong></li><li>Choose a new size<br> <em>(for example: </em><em>Standard_B2s)</em></li><li>Click <strong>Resize</strong></li></ol><p>If your VM is <strong>currently running</strong>, Azure will immediately show a warning.</p><p>And this warning is important.</p><p>By clicking <strong>Yes</strong>, you are explicitly allowing Azure to:</p><ul><li><strong>restart your VM</strong></li><li>temporarily stop all running applications</li><li>apply the new hardware configuration</li></ul><p>You don’t need to stop the VM yourself — <br> but you <strong>must understand</strong> that a restart will happen.</p><p>Once you confirm, Azure will:</p><ul><li>stop the VM</li><li>resize it</li><li>start it again automatically</li></ul><p>From your side, it’s just a few clicks.</p><p>But operationally, it’s a real restart — <br> and that’s why timing and verification still matter.</p><h3>But Here’s the Important Part: The VM Will Restart</h3><p>Even though Azure handles it for you, resizing <strong>always causes a restart</strong>.</p><p>That means:</p><ul><li>applications go down temporarily</li><li>open connections are dropped</li><li>in-memory data is lost</li></ul><p>So even though the UI feels easy, the impact is real.</p><p>This is where DevOps thinking starts.</p><h3>What You Must Think About Before Resizing a VM</h3><p>Changing VM size isn’t dangerous — <br><strong>changing it without thinking is</strong>.</p><p>Here are the key things to consider.</p><h3>1. If This Is Production, Timing Matters</h3><p>Never resize production VMs randomly.</p><p>Because resizing causes downtime, it’s best to do it during:</p><ul><li>low traffic hours</li><li>maintenance windows</li><li>late night or early morning (midnight is common)</li></ul><p>Even a 2–3 minute restart can affect users.</p><p>Plan first. Click later.</p><h3>2. Watch Out for Dynamic Public IP Addresses</h3><p>This one is critical and often forgotten.</p><p>If your VM uses a <strong>Dynamic Public IP</strong>:</p><ul><li>restarting the VM may change the IP</li><li>users may no longer reach your application</li><li>DNS records may suddenly be wrong</li></ul><p>If your service must stay reachable:</p><ul><li>use a <strong>Static Public IP</strong></li><li>or verify the IP after resize</li></ul><p>Many “app is down” incidents are actually just <strong>IP changes</strong>.</p><h3>3. A Running VM ≠ A Running Application</h3><p>After resize, Azure will start the VM automatically.</p><p>But:</p><ul><li>not all apps start automatically</li><li>some services may stay stopped</li><li>containers might not come up</li></ul><p>Before you mark the task as “done”, always:</p><ul><li>check application status</li><li>test endpoints</li><li>review logs</li></ul><p>The VM being “Running” only means the OS is alive — <br>not your business logic.</p><h3>4. Treat Resizing Like a Mini Maintenance Event</h3><p>A good mindset is this:</p><blockquote><em>Resizing a VM is small maintenance, not a casual click.</em></blockquote><p>That means:</p><ul><li>you know the impact</li><li>you verify afterward</li><li>you confirm everything works</li></ul><p>This habit separates beginners from reliable engineers.</p><h3>Final Thoughts: Simple Action, Smart Execution</h3><p>Azure makes resizing VMs easy — and that’s a good thing.</p><p>But real DevOps skill shows in:</p><ul><li><em>when</em> you resize</li><li><em>how</em> you plan it</li><li><em>what</em> you verify afterward</li></ul><p>Changing VM size is not just about performance.<br>It’s about <strong>responsibility</strong>.</p><p>Scale up carefully.<br>Verify thoroughly.<br>Then move on with confidence.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31a3df7f115a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Your Azure VM Gets Internet Access (Public IP, NIC, Explained Simply)]]></title>
            <link>https://medium.com/@randiadhityassaputra/how-your-azure-vm-gets-internet-access-public-ip-nic-explained-simply-83fcbf970401?source=rss-902c700e3176------2</link>
            <guid isPermaLink="false">https://medium.com/p/83fcbf970401</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[vm]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[nic]]></category>
            <dc:creator><![CDATA[Randi Adhityas Saputra]]></dc:creator>
            <pubDate>Sun, 11 Jan 2026 05:18:48 GMT</pubDate>
            <atom:updated>2026-01-11T05:23:59.196Z</atom:updated>
            <content:encoded><![CDATA[<p>When you create a Virtual Machine in Azure, many beginners assume one thing:</p><blockquote><em>“I created a VM, so my website should be accessible from the internet.”</em></blockquote><p>But then they try to open the website… and nothing works.</p><p>Why?</p><p>Because <strong>a VM without a Public IP is invisible to the internet</strong>.</p><p>Let’s break this down in a <strong>simple, human way</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*gP9Wr4Q6IybEKTetAtWOxA.png" /><figcaption>Generated using chatGPT</figcaption></figure><h3>Without a Public IP, Your Website Is NOT Public</h3><p>A Virtual Machine in Azure always gets:</p><ul><li>a <strong>private IP</strong> (inside Azure network)</li></ul><p>But a private IP:</p><ul><li>works only <strong>inside Azure</strong></li><li>cannot be accessed from your laptop or phone on the internet</li></ul><p>So:</p><ul><li>❌ No Public IP → No internet access</li><li>✅ Public IP → Internet can reach your server</li></ul><p>This is true for:</p><ul><li>websites</li><li>APIs</li><li>SSH / RDP access</li></ul><h3>But Azure Doesn’t Attach Public IP Directly to the VM</h3><p>This is where Azure feels “different” at first.</p><p>In Azure:</p><ul><li>Public IP is <strong>not attached to the VM</strong></li><li>It is attached to the <strong>Network Interface (NIC)</strong></li></ul><p>And that is <strong>by design</strong>.</p><h3>What Is a NIC (In Plain English)?</h3><p>A <strong>NIC (Network Interface Card)</strong> is what gives your VM:</p><ul><li>a private IP</li><li>access to the network</li><li>a path to the internet</li></ul><p>Think like this:</p><ul><li>VM = computer</li><li>NIC = network cable / Wi-Fi card</li><li>Public IP = your internet address</li></ul><p>You don’t connect the internet to the computer chip — <br> you connect it to the <strong>network card</strong>.</p><p>Azure works the same way.</p><h3>How Traffic Reaches Your Server (Simple Flow)</h3><p>When someone opens your website:</p><pre>Browser<br>  ↓<br>Public IP (Azure)<br>  ↓<br>NIC<br>  ↓<br>VM (your web server)</pre><p>The NIC acts like a <strong>gateway</strong>:</p><ul><li>it receives traffic from the Public IP</li><li>it forwards that traffic to the VM</li></ul><p>No NIC → no route<br>No Public IP → no internet</p><h3>Public IP Basics You Should Know (No Docs, Just Facts)</h3><h3>Public IP Is Regional</h3><ul><li>Public IP must be in the <strong>same Azure region</strong> as the VM</li><li>You cannot attach a Public IP from another region</li></ul><p>This is similar to <strong>AWS Elastic IP</strong>.</p><h3>Static vs Dynamic (Easy Rule)</h3><ul><li><strong>Static IP</strong> → IP never changes</li><li><strong>Dynamic IP</strong> → IP may change</li></ul><p>If your VM hosts anything real:</p><ul><li>website</li><li>API</li><li>SSH / RDP access</li></ul><p>👉 <strong>Always use Static Public IP</strong></p><h3>Where Can a Public IP Be Attached?</h3><p>Azure allows Public IP attachment to:</p><ul><li><strong>NIC</strong> → single VM</li><li><strong>Load Balancer</strong> → multiple VMs</li></ul><p>For beginners and most use cases:</p><blockquote><em>One VM = attach Public IP to </em><strong><em>NIC</em></strong></blockquote><p>Load Balancer is used later, when you care about:</p><ul><li>high availability</li><li>scaling</li><li>multiple backend servers</li></ul><h3>Before Attaching a Public IP: One Critical Check</h3><p>Every VM has at least <strong>one NIC</strong>.<br>Some VMs can have <strong>multiple NICs</strong>.</p><p>So before attaching a Public IP:</p><ul><li>open the VM</li><li>go to <strong>Networking</strong></li><li>note the <strong>exact NIC name</strong></li></ul><p>Attach the Public IP to the <strong>wrong NIC</strong>, and:</p><ul><li>everything looks correct</li><li>but nothing works</li></ul><p>This mistake happens more often than you think.</p><h3>Attaching a Static Public IP (Simple Portal Flow)</h3><p>Here’s the practical part, without over-complicating it:</p><ol><li>Open <strong>Azure Portal</strong></li><li>Go to <strong>Virtual Machines</strong></li><li>Open your VM</li><li>Click <strong>Networking</strong></li><li>Click the <strong>NIC name</strong></li><li>Open <strong>IP configurations</strong></li><li>Enable <strong>Public IP</strong></li><li>Select your <strong>Static Public IP</strong></li><li>Click <strong>Save</strong></li></ol><p>That’s it.</p><p>No VM restart.<br>No redeploy.<br>Just network wiring.</p><h3>“I Attached the IP but Still Can’t Access My Server”</h3><p>This is usually not an IP problem.</p><p>It’s a <strong>security rule problem</strong>.</p><p>Azure uses <strong>Network Security Groups (NSG)</strong>.<br> Think of NSG as:</p><blockquote><em>a firewall that blocks everything unless you allow it.</em></blockquote><p>Even with a Public IP:</p><ul><li>no NSG rule = no access</li></ul><p>So always check:</p><ul><li>SSH (22)</li><li>HTTP (80)</li><li>HTTPS (443)</li><li>RDP (3389)</li></ul><h3>Azure vs AWS vs GCP (Quick Mental Mapping)</h3><p>ConceptAzureAWSGCPVMVMEC2Compute EngineNetwork cardNICENIimplicitPublic IPPublic IPElastic IPExternal IPFirewallNSGSecurity GroupFirewall rule</p><p>Same ideas. Different names.</p><h3>Final Thoughts</h3><p>Azure networking often feels confusing at first — not because it’s complicated, but because <strong>Azure is very explicit</strong>.</p><p>Azure doesn’t assume things for you.</p><ul><li>It won’t automatically expose your VM to the internet</li><li>It won’t guess which NIC should get a Public IP</li><li>It won’t open ports unless you say so</li></ul><p>And honestly?<br>That’s a <strong>good thing</strong>.</p><p>Once you understand this simple idea:</p><blockquote><strong><em>Public IP gives internet access,<br>NIC delivers it to the VM</em></strong></blockquote><p>Everything else starts to make sense.</p><p>As a DevOps engineer, this mindset helps you:</p><ul><li>design safer architectures</li><li>avoid accidental exposure</li><li>debug connectivity issues faster</li></ul><h3>Fun Facts (That Actually Make You a Better DevOps Engineer)</h3><h3>🧠 Fun Fact #1:</h3><p>Many “Azure networking bugs” are not bugs at all<br>They’re just <strong>missing NIC or NSG wiring</strong>.</p><p>If something doesn’t work, always ask:</p><blockquote><em>“Where is the traffic supposed to flow?”</em></blockquote><h3>🔌 Fun Fact #2:</h3><p>You can delete and recreate a VM,<br>but keep the <strong>NIC and Public IP</strong> — and the IP stays the same.</p><p>This is why Azure separates everything:</p><ul><li>VM</li><li>NIC</li><li>Public IP</li></ul><p>👉 Infrastructure becomes reusable, not disposable.</p><h3>🔐 Fun Fact #3:</h3><p>A Public IP does <strong>nothing</strong> without NSG rules.</p><p>Public IP ≠ Open access<br>NSG decides who is allowed in.</p><p>That’s why Azure feels “secure by default”.</p><h3>☁️ Fun Fact #4:</h3><p>If you understand Azure NIC + Public IP,<br>moving to AWS or GCP becomes easier.</p><p>Different names, same idea:</p><ul><li>traffic needs a <strong>path</strong></li><li>security needs <strong>explicit permission</strong></li></ul><h3>🚨 DevOps Pro Tip</h3><p>When debugging access issues, always check in this order:</p><ol><li>Does the VM have a NIC?</li><li>Is the Public IP attached to the correct NIC?</li><li>Is the IP static?</li><li>Does NSG allow inbound traffic?</li><li>Is the service actually running?</li></ol><p>This checklist will save you <strong>hours</strong>.</p><h3>One Last Sentence to Remember</h3><blockquote><strong><em>In Azure, networking is not magic — it’s wiring.<br>If you wire it correctly, everything just works.</em></strong></blockquote><p>Happy building 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83fcbf970401" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Secure Your Internal Services with SSL Using Cloudflare (No More “Connection Not Secure”…]]></title>
            <link>https://medium.com/@randiadhityassaputra/how-to-secure-your-internal-services-with-ssl-using-cloudflare-no-more-connection-not-secure-ccf111950425?source=rss-902c700e3176------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccf111950425</guid>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[internal-https]]></category>
            <category><![CDATA[cloudflare]]></category>
            <category><![CDATA[dns-01]]></category>
            <category><![CDATA[https]]></category>
            <dc:creator><![CDATA[Randi Adhityas Saputra]]></dc:creator>
            <pubDate>Wed, 10 Dec 2025 10:25:50 GMT</pubDate>
            <atom:updated>2025-12-10T10:25:50.126Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Secure Your Internal Services with SSL Using Cloudflare (No More “Connection Not Secure” Warnings!)</h3><h3>The Problem</h3><p>Picture this: You’re connected to your company’s VPN, trying to access your Grafana dashboard at http://10.0.1.50:3000. Everything works fine, but that annoying &quot;Not Secure&quot; warning in your browser keeps bothering you. You want proper HTTPS with a valid certificate, but your server has an internal IP address that&#39;s not publicly accessible.</p><p>Sound familiar?</p><p>I ran into this exact issue. I wanted to access my Grafana monitoring dashboard through my VPN using an internal IP, but I was tired of dealing with self-signed certificates and browser security warnings. Here’s how I solved it using Cloudflare’s DNS-01 challenge method.</p><p>The beauty of this approach? Your server doesn’t need to be publicly accessible. Cloudflare validates your domain ownership through DNS records, not HTTP requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*g6bJph7ox8Tu6H4TJQwVaA.png" /></figure><h3>Prerequisites</h3><p>Before we begin, you’ll need:</p><ul><li>A domain managed by Cloudflare</li><li>A server with internal IP (accessible via VPN)</li><li>SSH access to your server</li><li>Docker installed on your server</li><li>Grafana (or any service) you want to secure</li></ul><h3>Step 1: Create a Cloudflare API Token</h3><ol><li>Log in to your Cloudflare Dashboard</li><li>Go to <strong>My Profile</strong> → <strong>API Tokens</strong></li><li>Click <strong>Create Token</strong></li><li>Use the <strong>Edit zone DNS</strong> template</li><li>Configure the token:</li></ol><ul><li><strong>Permissions</strong>: Zone — DNS — Edit</li><li><strong>Zone Resources</strong>: Include — Specific zone — example.com</li></ul><p>6. Click <strong>Continue to summary</strong> → <strong>Create Token</strong></p><p><strong>7. Copy the token immediately</strong> (you won’t see it again!)</p><p>Test your token to make sure it works:</p><pre>curl -X GET &quot;https://api.cloudflare.com/client/v4/user/tokens/verify&quot; \<br>  -H &quot;Authorization: Bearer YOUR_TOKEN_HERE&quot; \<br>  -H &quot;Content-Type: application/json&quot;</pre><p>You should see a success response with &quot;status&quot;:&quot;active&quot;.</p><h3>Step 2: Set Up DNS Records in Cloudflare</h3><p>Create an A record for your service:</p><ul><li>grafana.example.com → 10.0.1.50 (your internal IP)</li></ul><p><strong>Critical</strong>: Set this record to <strong>DNS only</strong> (gray cloud icon), NOT proxied through Cloudflare (orange cloud).</p><p>Verify DNS is working:</p><pre>dig +short grafana.example.com</pre><p>You should see your internal IP address in the output.</p><h3>Step 3: Install Certbot with Cloudflare Plugin</h3><h3>For Amazon Linux 2023/2</h3><p>Amazon Linux doesn’t have certbot-dns-cloudflare in its default repositories, so we&#39;ll install it via Python virtual environment:</p><pre># Install dependencies<br>sudo dnf install -y python3 python3-pip augeas-libs<br><br># Create virtual environment for certbot<br>sudo python3 -m venv /opt/certbot<br><br># Upgrade pip<br>sudo /opt/certbot/bin/pip install --upgrade pip<br><br># Install certbot and cloudflare plugin<br>sudo /opt/certbot/bin/pip install certbot certbot-dns-cloudflare<br><br># Create symlink for easy access<br>sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot</pre><p>Verify installation:</p><pre>certbot --version</pre><h3>For Ubuntu/Debian</h3><p>Ubuntu makes this much easier with native packages:</p><pre># Update package list<br>sudo apt update<br><br># Install certbot and cloudflare plugin<br>sudo apt install -y certbot python3-certbot-dns-cloudflare<br><br># Verify installation<br>certbot --version</pre><h3>Step 4: Configure Cloudflare Credentials</h3><p>Create a secure credentials file:</p><pre># Create secrets directory<br>sudo mkdir -p /root/.secrets</pre><pre># Create credentials file<br>sudo nano /root/.secrets/cloudflare.ini</pre><p>Add your API token (replace with your actual token):</p><pre># Cloudflare API token<br>dns_cloudflare_api_token = your_cloudflare_api_token_here</pre><p>Secure the file (very important!):</p><pre>sudo chmod 600 /root/.secrets/cloudflare.ini</pre><h3>Step 5: Request SSL Certificates</h3><p>Now for the magic! Request your certificate using DNS-01 validation:</p><pre>sudo certbot certonly \<br>  --dns-cloudflare \<br>  --dns-cloudflare-credentials /root/.secrets/cloudflare.ini \<br>  --dns-cloudflare-propagation-seconds 30 \<br>  -d grafana.example.com \<br>  --email your-email@example.com \<br>  --agree-tos \<br>  --non-interactive</pre><p>Your certificates will be saved in:</p><ul><li>/etc/letsencrypt/live/grafana.example.com/fullchain.pem</li><li>/etc/letsencrypt/live/grafana.example.com/privkey.pem</li></ul><h3>Step 6: Install and Configure Nginx</h3><p>Nginx will act as the <strong>reverse proxy</strong> in front of your application.<br>This step installs Nginx, enables it to run automatically at boot, and verifies that it is serving traffic correctly.</p><h3>Install Nginx</h3><p><strong>Amazon Linux 2023/2:</strong></p><pre># Install Nginx<br>sudo dnf install -y nginx<br><br># Enable Nginx to start on boot<br>sudo systemctl enable nginx<br><br># Start Nginx service<br>sudo systemctl start nginx<br><br># Check Nginx status<br>sudo systemctl status nginx</pre><p><strong>Ubuntu/Debian:</strong></p><pre># Update package list<br>sudo apt update<br><br># Install Nginx<br>sudo apt install -y nginx<br><br># Enable Nginx to start on boot<br>sudo systemctl enable nginx<br><br># Start Nginx service<br>sudo systemctl start nginx<br><br># Check Nginx status<br>sudo systemctl status nginx</pre><h3><strong>Verify Nginx is running:</strong></h3><p>Check if Nginx is listening on port 80 (HTTP)</p><p>Use either command below:</p><pre>sudo netstat -tulpn | grep :80</pre><p>or</p><pre>sudo ss -tulpn | grep :80</pre><p>Expected result:<br>You should see a process called <strong>nginx</strong> bound to port <strong>0.0.0.0:80</strong> or <strong>[::]:80</strong>.</p><h4>Test the Nginx configuration for syntax errors</h4><pre>sudo nginx -t</pre><p>You should see output like:</p><pre>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br>nginx: configuration file /etc/nginx/nginx.conf test is successful</pre><h3>Step 7: Configure Nginx for Grafana</h3><p>Create configuration file:</p><pre>sudo nano /etc/nginx/conf.d/grafana.conf</pre><p>Add this configuration:</p><pre>server {<br>    listen 80;<br>    server_name grafana.example.com;<br>    return 301 https://$server_name$request_uri;<br>}<br>server {<br>    listen 443 ssl;<br>    server_name grafana.example.com;<br>    ssl_certificate /etc/letsencrypt/live/grafana.example.com/fullchain.pem;<br>    ssl_certificate_key /etc/letsencrypt/live/grafana.example.com/privkey.pem;<br>    <br>    # Modern SSL configuration<br>    ssl_protocols TLSv1.2 TLSv1.3;<br>    ssl_ciphers HIGH:!aNULL:!MD5;<br>    ssl_prefer_server_ciphers on;<br>    ssl_session_cache shared:SSL:10m;<br>    ssl_session_timeout 10m;<br>    # Security headers<br>    add_header Strict-Transport-Security &quot;max-age=31536000&quot; always;<br>    location / {<br>        proxy_pass http://127.0.0.1:3000;<br>        proxy_set_header Host $host;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>    }<br>}</pre><h3>Test and Apply Nginx Configuration</h3><pre># Test configuration syntax<br>sudo nginx -t<br><br># If test passes, reload Nginx<br>sudo systemctl reload nginx</pre><h3>Step 8: Set Up Automatic Certificate Renewal</h3><h4>Install cron on Amazon Linux</h4><pre>sudo dnf install cronie -y</pre><h4>Enable and start the cron service</h4><pre>sudo systemctl enable crond<br>sudo systemctl start crond</pre><p>Check status:</p><pre>systemctl status crond</pre><p>You should see it running.</p><h3>Now edit root’s crontab</h3><pre>sudo crontab -e</pre><p>Add your Certbot renewal job:</p><pre>0 0,12 * * * /opt/certbot/bin/certbot renew --quiet --deploy-hook &quot;systemctl reload nginx&quot;</pre><p>Save → exit.</p><h3><strong>Verify</strong></h3><pre>sudo crontab -l</pre><h4>🧪 Optional: Test renewal</h4><pre>sudo /opt/certbot/bin/certbot renew --dry-run</pre><h3>Step 8: Verification and Testing</h3><p><strong>Check certificates are valid:</strong></p><pre>sudo certbot certificates</pre><p><strong>Test DNS resolution:</strong></p><pre>dig +short grafana.example.com</pre><p><strong>Test SSL connection:</strong></p><pre>curl -I https://grafana.example.com</pre><p><strong>Access your service:</strong></p><ul><li>Open your browser and navigate to <a href="https://grafana.example.com/">https://grafana.example.com</a></li><li>You should see a valid SSL certificate with no warnings!</li><li>Default Grafana login: admin / admin (change immediately)</li></ul><h3>Troubleshooting Common Issues</h3><h3>Issue: “DNS problem: NXDOMAIN”</h3><p><strong>Solution:</strong> Your DNS records aren’t propagated yet. Wait a few minutes or increase propagation time:</p><pre>sudo certbot certonly \<br>  --dns-cloudflare \<br>  --dns-cloudflare-credentials /root/.secrets/cloudflare.ini \<br>  --dns-cloudflare-propagation-seconds 60 \<br>  -d grafana.example.com \<br>  --email your-email@example.com \<br>  --agree-tos</pre><h3>Issue: “cannot load certificate”</h3><p><strong>Solution:</strong> Certificate path doesn’t exist. Check what was actually created:</p><pre>sudo ls -la /etc/letsencrypt/live/</pre><p>Update your Nginx config to match the actual directory name.</p><h3>Issue: “Cloudflare API authentication error”</h3><p><strong>Solution:</strong></p><ol><li>Verify your API token has <strong>Edit</strong> permissions (not just Read)</li><li>Check the token is for the correct zone</li><li>Ensure no extra spaces in cloudflare.ini</li></ol><h3>Issue: Nginx test fails with “http2” deprecated warning</h3><p><strong>Solution:</strong> Modern Nginx versions separated the http2 directive. Remove http2 from the listen line - it&#39;s not needed for basic HTTPS.</p><h3>Issue: Docker container won’t start</h3><p><strong>Solution:</strong> Check logs and common issues:</p><pre># View container logs<br>docker-compose logs grafana<br><br># Check if port is already in use<br>sudo netstat -tulpn | grep 3000<br><br># Restart Docker service<br>sudo systemctl restart docker<br>docker-compose up -d</pre><h3>Security Best Practices</h3><ol><li><strong>Keep certificates secure:</strong></li></ol><pre>sudo chmod 600 /root/.secrets/cloudflare.ini</pre><p><strong>2. Use strong SSL protocols:</strong></p><ul><li>Only TLSv1.2 and TLSv1.3</li><li>Disable weak ciphers</li></ul><p><strong>3. Bind services to localhost:</strong></p><ul><li>Docker: 127.0.0.1:3000:3000</li><li>Let only Nginx be publicly accessible</li></ul><p><strong>4. Regular backups of Docker volumes:</strong></p><ul><li>docker-compose down sudo tar -czf grafana-backup-$(date +%Y%m%d).tar.gz -C /var/lib/docker/volumes/grafana-ssl_grafana-data . docker-compose up -d</li></ul><p><strong>5. Monitor certificate expiration:</strong></p><pre>sudo certbot certificates</pre><p><strong>5. Keep Cloudflare records DNS-only:</strong></p><ul><li>Gray cloud icon (not proxied)</li><li>Avoids SSL/TLS handshake issues with internal IPs</li></ul><h3>Conclusion</h3><p>Now you can access your Grafana dashboard via VPN with a beautiful, valid SSL certificate — no more browser warnings! Your setup is secure, automated, and professionally configured.</p><p>The best part? Certificates auto-renew every 60 days, and your Grafana data is safely stored in Docker volumes, so this is truly a “set it and forget it” solution.</p><p>Key takeaways:</p><ul><li>✅ DNS-01 validation works with internal IPs</li><li>✅ No need for publicly accessible servers</li><li>✅ Automatic certificate renewal</li><li>✅ Professional SSL configuration</li><li>✅ No more “Connection Not Secure” warnings</li></ul><p>Happy secure browsing! 🔒</p><p><em>Have questions or run into issues? Drop a comment below and I’ll help you troubleshoot!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccf111950425" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ How to Increase EC2 Disk Size on Amazon Linux (Without Restart) — Complete Guide]]></title>
            <link>https://medium.com/@randiadhityassaputra/how-to-increase-ec2-disk-size-on-amazon-linux-without-restart-complete-guide-febda0513a50?source=rss-902c700e3176------2</link>
            <guid isPermaLink="false">https://medium.com/p/febda0513a50</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[disk]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ubuntu-server]]></category>
            <category><![CDATA[ec2]]></category>
            <dc:creator><![CDATA[Randi Adhityas Saputra]]></dc:creator>
            <pubDate>Mon, 08 Dec 2025 02:03:49 GMT</pubDate>
            <atom:updated>2025-12-08T02:03:49.839Z</atom:updated>
            <content:encoded><![CDATA[<h3>🚀 How to Increase EC2 Disk Size on Amazon Linux (Without Restart) — Complete Guide</h3><p>Running out of disk space on an EC2 instance is extremely common — especially when using Docker, databases, or heavy logs. The good news is:</p><blockquote><strong><em>You can safely expand your EC2 disk without restarting or stopping your server.</em></strong></blockquote><p>This guide walks through the exact steps to increase an EC2 root volume (EBS) and resize the filesystem <strong>live</strong>, using Amazon Linux.<br> These steps also apply to Ubuntu and Debian (with small differences noted below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*TKe1eu3eM8Q-JTJgaLjlsw.png" /></figure><h3>🟦 Why No Restart Is Needed?</h3><p>AWS EBS volumes support <strong>online expansion</strong>.<br> This means:</p><ul><li>You increase the disk in AWS Console</li><li>Resize the partition from inside the instance</li><li>Grow the filesystem</li></ul><p>✔ No reboot<br> ✔ No service interruption<br> ✔ No downtime</p><p>Both XFS (Amazon Linux) and EXT4 (Ubuntu) support online filesystem growth.</p><h3>🟨 Step 1 — Increase Disk Size in AWS (No Restart Needed)</h3><ol><li>Go to <strong>AWS EC2 Console</strong></li><li>Open your <strong>instance</strong></li><li>Click <strong>Storage</strong></li><li>Select the root volume (usually /dev/nvme0n1)</li><li>Click <strong>Actions → Modify Volume</strong></li><li>Increase the size<br> Example: <strong>15GB → 25GB</strong></li><li>Click <strong>Modify → Yes</strong></li></ol><p>The volume expands instantly.<br> AWS does <em>not</em> reboot your EC2 instance for this change.</p><h3>🟩 Step 2 — Log Into the Server and Inspect the Disk</h3><p>SSH into the EC2 instance:</p><pre>ssh ec2-user@yourserver</pre><h3>📌 Command: lsblk</h3><pre>sudo lsblk</pre><p><strong>What this command does:</strong><br> Shows block devices (disks, partitions, volumes). Essential for checking whether the OS can see the increased AWS disk size.</p><h3>Example output:</h3><pre>NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS<br>nvme0n1       259:0    0   25G  0 disk<br>├─nvme0n1p1   259:1    0   15G  0 part /<br>├─nvme0n1p127 259:2    0    1M  0 part<br>└─nvme0n1p128 259:3    0   10M  0 part /boot/efi</pre><h3>Interpretation:</h3><ul><li><strong>Disk (</strong><strong>nvme0n1)</strong> is now 25GB → AWS increase worked</li><li><strong>Partition (</strong><strong>nvme0n1p1)</strong> still 15GB → must expand</li><li><strong>Filesystem (/)</strong> still 15GB → must grow</li></ul><h3>🟦 Step 3 — Expand the Partition (Safe Live Operation)</h3><p>Use the growpart command from the cloud-utils-growpart package (pre-installed on Amazon Linux).</p><h3>📌 Command:</h3><pre>sudo growpart /dev/nvme0n1 1</pre><h3>What it does:</h3><ul><li>Expands <strong>partition 1</strong> on disk <strong>nvme0n1</strong></li><li>Makes the partition fill the newly increased space</li><li>Does <strong>not</strong> affect running processes</li><li>Does <strong>not</strong> require reboot</li></ul><h3>Verify:</h3><pre>sudo lsblk</pre><p>You should now see nvme0n1p1 expanded to the new size.</p><h3>🟩 Step 4 — Determine Filesystem Type</h3><p>Before resizing the filesystem, confirm the type:</p><pre>sudo file -s /dev/nvme0n1p1<br></pre><p>Example output:</p><pre>/dev/nvme0n1p1: SGI XFS filesystem data (blksz 4096, inosz 512, v2 dirs)</pre><p>You will see something like:</p><ul><li>SGI XFS filesystem → Amazon Linux</li><li>EXT4 filesystem → Ubuntu/Debian</li></ul><h3>🟦 Understanding Step 5 — How Filesystem Expansion Works (With Diagram)</h3><p>When you increase the disk size in AWS, three layers are involved:</p><pre>┌───────────────────────────┐<br>│   Layer 1: Physical Disk  │  ← AWS expands this<br>│   (EBS Volume)            │<br>└───────────────────────────┘<br>             │<br>             ▼<br>┌───────────────────────────┐<br>│   Layer 2: Partition      │  ← growpart expands this<br>│   (/dev/nvme0n1p1)        │<br>└───────────────────────────┘<br>             │<br>             ▼<br>┌───────────────────────────┐<br>│   Layer 3: Filesystem     │  ← YOU expand this (Step 5)<br>│   (XFS or EXT4)           │<br>└───────────────────────────┘</pre><ul><li>AWS only enlarges <strong>Layer 1</strong>.</li><li>growpart enlarges <strong>Layer 2</strong>.</li><li>Now in Step 5, you expand <strong>Layer 3</strong> so Linux can use the new disk space.</li></ul><h3>🟥 Step 5 — Expand the Filesystem (Live, No Downtime)</h3><p>Once the partition has been expanded with growpart, the last step is to grow the filesystem so your system can actually use the new disk space. This can also be done <strong>live</strong>, without unmounting / and without restarting the instance.</p><p>Before resizing, detect which filesystem your root partition uses:</p><pre>sudo file -s /dev/nvme0n1p1</pre><p>Depending on the output, use the appropriate command below.</p><h3>✔ For Amazon Linux (XFS Filesystem)</h3><p>Most Amazon Linux and Amazon Linux 2 systems use <strong>XFS</strong> for the root filesystem.<br> XFS supports <strong>online growth</strong>, meaning you can expand it safely while the system is running.</p><pre>sudo xfs_growfs /</pre><h3>What this command does:</h3><ul><li>Grows the <strong>mounted</strong> filesystem on /</li><li>Expands it to fill all available space in the enlarged partition</li><li>Applies immediately — no restart required</li><li>Completely safe for running applications, Docker, databases, etc.</li></ul><p>This is the recommended method for Amazon Linux because XFS is extremely stable and designed for large-volume, online expansion.</p><h3>✔ For Ubuntu / Debian (EXT4 Filesystem)</h3><p>If your server uses EXT4 instead of XFS (very common on Ubuntu), use:</p><pre>sudo resize2fs /dev/nvme0n1p1</pre><h3>Why this works:</h3><ul><li>EXT4 also supports online resizing when mounted</li><li>resize2fs automatically expands the filesystem to use all the free space in the resized partition</li><li>No need to unmount /</li><li>No reboot required</li></ul><h3>🟧 Step 6 — Verify the Expanded Disk</h3><pre>df -h</pre><p>You should now see the new size:</p><pre>Filesystem      Size  Used Avail Use%<br>/dev/nvme0n1p1   25G  7.5G   17G  32% /</pre><h3>🎉 Final Result</h3><p>You have successfully:</p><ul><li>Expanded the AWS EBS volume</li><li>Resized the Linux partition</li><li>Grown the filesystem</li></ul><p>✔ All <strong>without restarting</strong><br> ✔ Without downtime<br> ✔ Without stopping any services</p><p>This method works for:</p><ul><li>Amazon Linux</li><li>Amazon Linux 2</li><li>Ubuntu</li><li>Debian</li><li>Any EC2 instance using EBS volumes</li></ul><h3>🔧 Extra: Explanation of Every Command</h3><p><strong>lsblk</strong><br>Shows all disks and partitions on the system. This helps you confirm that AWS has already expanded the root volume size.</p><p><strong>growpart /dev/nvme0n1 1</strong><br>Expands partition <strong>1</strong> on the disk so it can use the newly added space. This updates the partition layout <em>without requiring a reboot</em>.</p><p><strong>file -s /dev/nvme0n1p1</strong><br>Displays the filesystem type (XFS or EXT4). Amazon Linux uses XFS by default, Ubuntu/Debian often use EXT4. You need this to choose the correct grow command.</p><p><strong>xfs_growfs /</strong><br>Expands an <strong>XFS</strong> filesystem live while the instance is running. No need to unmount or restart — perfect for Amazon Linux.</p><p><strong>resize2fs /dev/nvme0n1p1</strong><br>Expands an <strong>EXT4</strong> filesystem (used in Ubuntu, Debian). This also works online without stopping the system.</p><p><strong>df -h</strong><br>Shows the final available disk space after the resize. Use this to confirm that the new size is applied correctly.</p><h3>🚀 Closing Thoughts</h3><p>Resizing an AWS EC2 disk doesn’t have to be scary — and the best part is that you can do it <strong>live, without any downtime or reboot</strong>. Whether you’re using Amazon Linux with XFS or Ubuntu with EXT4, the steps are simple once you understand what each command does.</p><p>If this guide helped you, feel free to <strong>follow me on Medium</strong> for more DevOps, AWS, and backend tutorials.<br> I share practical, real-world fixes just like this one every week. 👇</p><p>👉 <strong>Follow me on Medium for more tips!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=febda0513a50" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>