<?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 Anubhav Bhatt on Medium]]></title>
        <description><![CDATA[Stories by Anubhav Bhatt on Medium]]></description>
        <link>https://medium.com/@anubhavbhatt?source=rss-9379711ef44------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*q8sIu6G7hys3NAuYfHPCjA.png</url>
            <title>Stories by Anubhav Bhatt on Medium</title>
            <link>https://medium.com/@anubhavbhatt?source=rss-9379711ef44------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 09:18:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anubhavbhatt/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[DevOps Concepts 17/25 — Ansible Architecture: Understanding Agentless Automation]]></title>
            <link>https://medium.com/@anubhavbhatt/devops-concepts-17-25-ansible-architecture-understanding-agentless-automation-f73a3ebd0f10?source=rss-9379711ef44------2</link>
            <guid isPermaLink="false">https://medium.com/p/f73a3ebd0f10</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <dc:creator><![CDATA[Anubhav Bhatt]]></dc:creator>
            <pubDate>Tue, 17 Nov 2026 05:41:01 GMT</pubDate>
            <atom:updated>2026-11-17T05:41:01.545Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HE57Rfx-ZV6dIhHWkRxFAg.png" /></figure><p>This is Article 17 of 25 in the DevOps Concepts Series (Part 5 of 6: Configuration Management with Ansible). Terraform creates the servers. Something still has to install packages, write config files and start services on them, and Ansible does that over plain SSH.</p><h4>Key Takeaways</h4><pre>- Ansible is agentless: a control node pushes small Python modules to managed nodes over SSH and removes them afterwards.<br> - Inventory says which hosts exist, playbooks say what state they should be in, modules do the actual work.<br> - Tasks describe desired state, not commands, so running a playbook twice should change nothing the second time (idempotency).<br> - Run with --check and --diff before touching real servers.<br> - Keep secrets in Ansible Vault, never in plain inventory or playbook files.<br> - Use the command and shell modules only when no dedicated module exists, because they are not idempotent by default.</pre><h3>What is configuration management?</h3><p>Provisioning gives you a blank machine. Configuration management turns it into the machine you want: Nginx installed, the firewall open on port 80 and 443 only, the application code in place, the service running.</p><p>Doing that by hand over SSH works for one server. For ten servers it produces drift: one host has a newer package, another is missing a firewall rule, nobody remembers why. A configuration management tool lets you write the desired state once, store it in Git, and apply it to every host the same way.</p><h3>Why is Ansible agent-less?</h3><p>Older tools such as Puppet and Chef run an agent on every managed machine. The agent polls a central server, pulls its configuration and applies it. That means installing software on each host, keeping it upgraded, and opening a port or maintaining a certificate for the agent.</p><p>Ansible takes the other route:</p><ul><li>Agent-based: a daemon runs permanently on each node and pulls its config.</li><li>Agentless: nothing runs on the node between runs. The control node connects when you ask it to, does the work, and disconnects.</li></ul><p>The only requirements on a managed Linux node are an SSH server and Python. If you can SSH in, Ansible can manage the host. That is why teams can start using it on servers that already exist, without a rollout step.</p><p>The trade-off is that nothing watches the host between runs. If someone edits a file by hand tomorrow, Ansible will not notice until the next run. You schedule runs, or trigger them from CI, to catch that.</p><h3>What are the parts of Ansible?</h3><ul><li>Control node: the machine where you run ansible or ansible-playbook. It needs Ansible installed. It can be your laptop or a CI runner. Windows is not supported as a control node.</li><li>Managed nodes: the servers being configured. No Ansible install needed.</li><li>Inventory: the list of managed nodes, optionally grouped.</li><li>Playbook: a YAML file with one or more plays. Each play maps a group of hosts to an ordered list of tasks.</li><li>Task: one call to one module with arguments.</li><li>Module: a small unit of code that does one thing, such as ansible.builtin.apt, ansible.builtin.copy or ansible.posix.firewalld.</li><li>Plugin: code that extends Ansible itself, such as connection plugins, inventory plugins, lookup plugins and callback plugins.</li></ul><h3>How does the architecture fit together?</h3><pre>Control node<br> ├─ ansible.cfg<br> ├─ inventory/hosts.ini        which servers, in which groups<br> ├─ playbooks/site.yml         what state they should be in<br> └─ Ansible core + modules<br>        │<br>        │  SSH (default), one connection per host, in parallel (forks)<br>        ▼<br>Managed nodes: web1, web2, web3<br> └─ Python + sshd only</pre><p>Communication is plain SSH, using keys. By default Ansible runs up to five hosts in parallel (the forks setting), so a hundred hosts are processed in batches unless you raise it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzQyBRiI1KM_vxPwQPm4Nw.png" /></figure><h3>How does Ansible execute a task?</h3><p>For each task, on each host, Ansible does roughly this:</p><p>1. Reads the playbook and resolves variables for the host.</p><p>2. Opens an SSH connection (reusing it where possible).</p><p>3. Copies the module as a temporary Python script to a temp directory on the node.</p><p>4. Runs the module on the node with the task arguments.</p><p>5. The module checks current state, changes it only if it differs from the desired state, and returns JSON: changed, failed, and details.</p><p>6. Ansible deletes the temp script and records the result.</p><p>The play recap at the end summarises this per host as ok, changed, unreachable, failed and skipped.</p><h3>What is idempotency?</h3><p>Idempotency means applying the same task repeatedly leaves the system in the same state. Compare:</p><pre># Not idempotent: appends the line every time it runs<br>echo &quot;net.ipv4.ip_forward=1&quot; &gt;&gt; /etc/sysctl.conf</pre><pre># Idempotent: ensures the line exists exactly once<br>- name: Enable IP forwarding<br>  ansible.builtin.lineinfile:<br>    path: /etc/sysctl.conf<br>    line: net.ipv4.ip_forward=1</pre><p>The first run reports changed. A second run reports ok. That ok is the signal that the host already matches the playbook, and it is what makes Ansible safe to run on a schedule.</p><h3>Hands-on: configure three Linux servers</h3><p>Goal: on three Ubuntu servers install Nginx, open the firewall for web traffic, and deploy a small application page.</p><h4>Project layout</h4><pre>ansible-demo/<br>├── ansible.cfg<br>├── inventory/<br>│   └── hosts.ini<br>├── files/<br>│   └── index.html<br>└── site.yml</pre><h4>ansible.cfg</h4><pre>[defaults]<br>inventory = inventory/hosts.ini<br>remote_user = deploy<br>host_key_checking = True<br>forks = 10</pre><pre>[privilege_escalation]<br>become = True</pre><p>remote_user is the SSH user. become = True makes tasks run through sudo, since installing packages needs root. forks raises the parallel host count from the default.</p><h4>inventory/hosts.ini</h4><pre>[web]<br>web1 ansible_host=10.0.1.11<br>web2 ansible_host=10.0.1.12<br>web3 ansible_host=10.0.1.13</pre><pre>[web:vars]<br>app_name=taskflow<br>http_port=80</pre><p>[web] is a group of three hosts. [web:vars] sets variables for every host in the group. ansible_host is the address Ansible connects to, which lets the inventory name differ from the IP.</p><p>Check connectivity before writing any playbook:</p><pre>ansible web -m ansible.builtin.ping</pre><p>A pong from each host confirms SSH and Python both work.</p><h4>site.yml</h4><pre>---<br>- name: Configure web servers<br>  hosts: web<br>  become: true</pre><pre>  tasks:<br>    - name: Install Nginx and UFW<br>      ansible.builtin.apt:<br>        name:<br>          - nginx<br>          - ufw<br>        state: present<br>        update_cache: true<br>        cache_valid_time: 3600</pre><pre>    - name: Allow SSH through the firewall<br>      community.general.ufw:<br>        rule: allow<br>        port: &quot;22&quot;<br>        proto: tcp</pre><pre>    - name: Allow HTTP and HTTPS<br>      community.general.ufw:<br>        rule: allow<br>        port: &quot;{{ item }}&quot;<br>        proto: tcp<br>      loop:<br>        - &quot;80&quot;<br>        - &quot;443&quot;</pre><pre>    - name: Enable the firewall with default deny<br>      community.general.ufw:<br>        state: enabled<br>        policy: deny</pre><pre>    - name: Deploy the application page<br>      ansible.builtin.template:<br>        src: index.html.j2<br>        dest: /var/www/html/index.html<br>        owner: www-data<br>        group: www-data<br>        mode: &quot;0644&quot;<br>      notify: Reload Nginx</pre><pre>    - name: Make sure Nginx is running and enabled at boot<br>      ansible.builtin.service:<br>        name: nginx<br>        state: started<br>        enabled: true</pre><pre>  handlers:<br>    - name: Reload Nginx<br>      ansible.builtin.service:<br>        name: nginx<br>        state: reloaded</pre><p>Create templates/index.html.j2 next to the playbook:</p><pre>&lt;h1&gt;{{ app_name }} on {{ inventory_hostname }}&lt;/h1&gt;</pre><p>Allow SSH before enabling the firewall. If you enable it first with default deny, you lock yourself out of the host.</p><h4>Run it</h4><pre>ansible-playbook site.yml --check --diff   # dry run, show file diffs<br>ansible-playbook site.yml                  # apply<br>ansible-playbook site.yml                  # run again: expect changed=0</pre><p>On the first real run the recap shows changed for each host. On the second run the changed count should be 0, which proves the tasks are idempotent.</p><h3>Configuration breakdown</h3><ul><li>hosts: web selects the inventory group the play targets. It can be a group, a host, a pattern such as web:!web3, or all.</li><li>become: true escalates privileges for the whole play. You can also set it per task.</li><li>ansible.builtin.apt with state: present installs a package if absent. state: latest upgrades and breaks repeatability, so use it deliberately.</li><li>loop repeats a task for each item, exposed as item.</li><li>template renders a Jinja2 file with host variables and copies the result. It reports changed only when the rendered content differs.</li><li>notify queues a handler. Handlers run once at the end of the play, and only if a task that notified them reported changed. This stops Nginx reloading on every run.</li><li>--check simulates changes without applying them. --diff shows what would change in files. Some modules cannot predict changes in check mode, so treat it as a strong hint, not a guarantee.</li></ul><h3>How do you keep credentials secure?</h3><p>SSH access should use keys, not passwords. For secrets the playbook itself needs, such as a database password, use Ansible Vault:</p><pre>ansible-vault create group_vars/web/vault.yml<br>ansible-vault edit group_vars/web/vault.yml<br>ansible-playbook site.yml --ask-vault-pass</pre><p>The file is encrypted at rest, so it is safe to commit. In CI, supply the vault password from the pipeline’s secret store through --vault-password-file rather than typing it. Add no_log: true to tasks that handle secrets so values do not appear in the output.</p><h3>Where do teams use Ansible?</h3><ul><li>Baseline hardening of new servers: users, SSH settings, firewall, time sync, package updates.</li><li>Installing and configuring middleware: Nginx, PostgreSQL, Redis, monitoring agents.</li><li>Rolling deployments across a group, using serial to update a few hosts at a time.</li><li>Day-two tasks such as rotating certificates or restarting a service across a fleet.</li><li>Following Terraform: Terraform creates the instances, Ansible configures what runs on them.</li></ul><h3>Common mistakes</h3><ul><li>Using shell or command for everything. Those modules always report changed unless you add creates, removes or changed_when, so you lose the idempotency signal.</li><li>Enabling a firewall before allowing SSH, then locking yourself out.</li><li>Committing plain-text passwords in inventory or group_vars.</li><li>Setting host_key_checking = False permanently. It removes protection against a man-in-the-middle; use it only in throwaway labs.</li><li>Writing one very long playbook with everything inline. That is the problem roles solve, covered in the next article.</li><li>Forgetting Python on minimal images, which gives errors like “/usr/bin/python: not found”.</li></ul><p>Debugging tips: add -v, -vvv for connection details, use ansible-inventory --graph to see how hosts are grouped, and ansible web -m ansible.builtin.setup to dump the facts Ansible gathers from a host.</p><h3>Best practices</h3><ul><li>Keep inventory, playbooks and templates in Git and review changes like code.</li><li>Prefer dedicated modules over shell.</li><li>Use fully qualified module names such as ansible.builtin.copy.</li><li>Always dry-run with --check --diff against production.</li><li>Limit blast radius with --limit web1 for a canary, then run the rest.</li><li>Run ansible-lint in CI.</li><li>Name every task so the output reads like a changelog.</li></ul><h3>Challenge</h3><p>Add a task that installs fail2ban and starts it, then run the playbook twice. Confirm the second run reports changed=0 for every host.</p><h3>Related in this series</h3><ul><li>Previous: DevOps Concepts 16/25 — GitHub Branching Strategy: Choosing the Right Workflow for Your Team</li><li>Next: DevOps Concepts 18/25 — Ansible Roles: Building Reusable and Maintainable Automation</li><li>Also see: DevOps Concepts 19/25 — Ansible Dynamic Inventory: Managing Changing Infrastructure Automatically</li></ul><p>This is Article 17 of 25 in the DevOps Concepts Series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f73a3ebd0f10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevOps Concepts 16/25 — GitHub Branching Strategy: Choosing the Right Workflow for Your Team]]></title>
            <link>https://medium.com/@anubhavbhatt/devops-concepts-16-25-github-branching-strategy-choosing-the-right-workflow-for-your-team-781b898a5692?source=rss-9379711ef44------2</link>
            <guid isPermaLink="false">https://medium.com/p/781b898a5692</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Anubhav Bhatt]]></dc:creator>
            <pubDate>Mon, 16 Nov 2026 05:41:01 GMT</pubDate>
            <atom:updated>2026-11-16T05:41:01.599Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PxypUSV4jWbSP1bczeTc6Q.png" /></figure><p>This is Article 16 of 25 in the DevOps Concepts Series (Part 4 of 6: CI/CD &amp; Git Workflows). The pipelines from the last two articles only help if the team agrees on how code reaches the main branch. This article compares the three common branching strategies and ends with a GitHub Flow setup you can copy.</p><h4>Key Takeaways</h4><pre>- A branching strategy decides how changes are isolated, reviewed, released and fixed in production.<br> - Git Flow uses long-lived develop and release branches and suits scheduled, versioned releases.<br> - GitHub Flow uses short feature branches off main and deploys from main; it suits continuous delivery.<br> - Trunk-based development merges tiny changes to main daily and relies on feature flags and strong CI.<br> - Branch protection turns the strategy into enforced rules: required reviews, required checks, no force pushes.<br> - Pick the simplest model your release process allows; complexity in branching is a cost every day.</pre><h3>Why does a branching strategy matter?</h3><p>Git lets you branch freely, which is exactly the problem. Without a shared convention, one developer keeps a feature branch for six weeks, another commits straight to main, and a hotfix gets applied in three places. The strategy answers four questions:</p><ul><li>Where does new work start?</li><li>How does it get reviewed and tested?</li><li>How does it reach production?</li><li>How do you fix something that is already live?</li></ul><h3>The common branch types</h3><ul><li><strong>main</strong> (or master): the source of truth. In most models it should always be releasable.</li><li><strong>feature branches</strong>: short-lived branches for one change, such as feature/login-rate-limit.</li><li><strong>release branches</strong>: a stabilization branch cut when preparing a version.</li><li><strong>hotfix branches</strong>: urgent fixes branched from what is in production.</li></ul><p>Different strategies use different subsets of these.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-wX1I2lOeW9PXsIM1bwKFQ.png" /></figure><h3>Git Flow</h3><p>Git Flow has two permanent branches, main and develop, plus supporting branches.</p><p>1. Features branch from develop and merge back into develop.</p><p>2. When enough is ready, a release/1.4 branch is cut from develop for final testing and fixes.</p><p>3. The release branch is merged into main, tagged v1.4, and merged back into develop.</p><p>4. A production bug gets a hotfix/ branch from main, merged into both main and develop.</p><p>Strengths: clear separation between what is in development and what is released, and a natural place to stabilize a version. It fits software with versioned releases, multiple supported versions or long QA cycles, such as mobile apps or installed software.</p><p>Weaknesses: more branches mean more merges and more drift. Merge conflicts grow with branch lifetime. It works against continuous deployment because “what is on main” is not what is being built every day.</p><h3>GitHub Flow</h3><p>GitHub Flow is deliberately small:</p><p>1. main is always deployable.</p><p>2. Create a short-lived branch from main with a descriptive name.</p><p>3. Commit, push and open a pull request.</p><p>4. Automated checks run and someone reviews.</p><p>5. Merge to main.</p><p>6. Deploy from main (often automatically).</p><p>There is no develop branch and no release branch. A hotfix is just another small branch and pull request. Strengths: simple to teach, fits web services deployed many times a day. Weakness: it assumes you can deploy main at any time and have good automated tests, and it gives no built-in structure for supporting several released versions.</p><h3>Trunk-based development</h3><p>Trunk-based development goes further. Developers commit to main (the trunk) directly or through very short-lived branches that last hours, not days, and integrate at least daily.</p><ul><li>Incomplete work is hidden behind <strong>feature flags</strong> so it can merge without being visible to users.</li><li>Large changes are broken into small steps, sometimes using branch by abstraction.</li><li>Releases are cut from the trunk, either continuously or via a short release branch or tag.</li><li>CI must be fast and reliable, because everything lands on the same branch.</li></ul><p>Strengths: minimal merge pain, fast feedback, and a natural fit for continuous delivery. Weaknesses: needs a disciplined team, strong automated testing and feature-flag hygiene, and it can be uncomfortable without them.</p><h3>Pull request workflows</h3><p>Whichever strategy you choose, pull requests are where quality is enforced:</p><ul><li>Keep them small. A 100-line change gets read; a 2,000-line change gets approved without reading.</li><li>Describe why, not just what. Link the issue.</li><li>Let automation handle style and obvious errors so humans review design and correctness.</li><li>Merge method matters: squash merge gives one commit per change and a clean history, merge commits preserve the branch shape, and rebase merge keeps a linear history. Pick one default and write it down.</li></ul><h3>Branch protection rules</h3><p>Strategy only holds if the platform enforces it. In GitHub, use branch protection rules or rulesets on main (and release/* if you use them):</p><ul><li>Require a pull request before merging, with at least one approving review.</li><li>Require status checks to pass, for example the CI job from Article 14, and require branches to be up to date.</li><li>Dismiss stale approvals when new commits are pushed.</li><li>Require review from code owners for sensitive paths using a CODEOWNERS file.</li><li>Block force pushes and branch deletion.</li><li>Require linear history if you squash or rebase.</li><li>Apply the rules to administrators too, so the rule is real.</li></ul><h3>Hands-on: implement GitHub Flow</h3><p>We will set this up for taskflow.</p><p>Step 1: add a CI workflow that runs on pull requests (shortened from Article 14):</p><pre>name: CI<br>on:<br>  pull_request:<br>    branches: [main]<br>  push:<br>    branches: [main]</pre><pre>permissions:<br>  contents: read</pre><pre>jobs:<br>  test:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - uses: actions/setup-python@v5<br>        with:<br>          python-version: &quot;3.12&quot;<br>          cache: pip<br>      - run: pip install -r requirements.txt<br>      - run: pytest</pre><p>Step 2: add a CODEOWNERS file:</p><pre># .github/CODEOWNERS<br>*            @my-org/backend-team<br>/infra/      @my-org/platform-team<br>/.github/    @my-org/platform-team</pre><p>Step 3: protect main in repository settings (or with the GitHub CLI and API) with the rules above, marking the test check as required.</p><p>Step 4: the developer loop:</p><pre>git switch main &amp;&amp; git pull<br>git switch -c feature/add-task-priority<br># make changes, commit in small steps<br>git push -u origin feature/add-task-priority<br>gh pr create --fill</pre><p>Step 5: CI runs on the pull request, a reviewer approves, and the PR is squash merged. Deleting the branch after merge keeps the repository tidy; GitHub can do that automatically.</p><p>Step 6: deploy from main. The push to main triggers the build-and-deploy workflow, and production deploys require the environment approval from Article 14.</p><p>For a production hotfix the process does not change: branch from main, fix, open a PR, let checks run, merge, and deploy. It can be fast because the process is already short.</p><h3>Release management</h3><ul><li>Tag releases with semantic versions (v1.4.2) so artifacts, changelogs and rollbacks have a reference point.</li><li>Use GitHub Releases to attach notes and artifacts to a tag.</li><li>In GitHub Flow and trunk-based development the deployed image is tagged with the commit SHA, and release tags mark meaningful milestones.</li><li>In Git Flow, the release branch is where version numbers, changelogs and last-minute fixes happen.</li></ul><h3>How to choose</h3><ul><li><strong>Early-stage startup or very small team</strong>: GitHub Flow. Small surface area, one long-lived branch, fast shipping.</li><li><strong>Small to mid-size product team with continuous delivery</strong>: GitHub Flow, moving toward trunk-based as test coverage and feature flags mature.</li><li><strong>Larger organization with strong CI, many engineers and daily integration</strong>: trunk-based development, often with short-lived branches and flags.</li><li><strong>Versioned software, multiple supported releases, or regulated release gates</strong>: Git Flow or a simplified variant with release branches only.</li></ul><p>Frequency of delivery is the main signal. The more often you can safely release, the fewer long-lived branches you need.</p><h3>Common mistakes</h3><ul><li><strong>Long-lived feature branches.</strong> The longer a branch lives, the worse the merge. Split work or use feature flags.</li><li><strong>Adopting Git Flow for a service that deploys continuously.</strong> You pay the complexity and get none of the benefit.</li><li><strong>Branch protection without required checks.</strong> Reviews alone do not catch broken builds.</li><li><strong>Allowing admins to bypass everything.</strong> The urgent bypass becomes the habit.</li><li><strong>Giant pull requests.</strong> They slow reviews and hide bugs.</li><li><strong>Skipping feature flags in trunk-based development.</strong> Without them, half-finished code reaches users or blocks merging.</li><li><strong>Unclear naming.</strong> Agree on feature/, fix/ and hotfix/ prefixes and issue references.</li></ul><h3>Best practices</h3><ul><li>Keep main always releasable and protected.</li><li>Keep branches short, ideally merged within a day or two.</li><li>Make CI fast and reliable, since every strategy leans on it.</li><li>Write the strategy down in the repository (CONTRIBUTING.md) so new people follow the same rules.</li><li>Review the strategy when team size or release cadence changes.</li></ul><h3>Challenge</h3><p>On a test repository, enable branch protection on main requiring one review and a passing check. Try to push directly to main, then open a pull request that fails CI, and confirm the merge button stays blocked.</p><h3>Related in this series</h3><ul><li>Previous: DevOps Concepts 15/25 — GitHub Actions Optimization: Building Faster and More Efficient Pipelines</li><li>Next: DevOps Concepts 17/25 — Ansible Architecture: Understanding Agentless Automation</li><li>Related: DevOps Concepts 14/25 — GitHub Actions Workflow: Understanding CI/CD Automation</li></ul><p>This is Article 16 of 25 in the DevOps Concepts Series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=781b898a5692" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevOps Concepts 15/25 — GitHub Actions Optimization: Building Faster and More Efficient Pipelines]]></title>
            <link>https://medium.com/@anubhavbhatt/devops-concepts-15-25-github-actions-optimization-building-faster-and-more-efficient-pipelines-e2779520fd2c?source=rss-9379711ef44------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2779520fd2c</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Anubhav Bhatt]]></dc:creator>
            <pubDate>Sun, 15 Nov 2026 05:41:01 GMT</pubDate>
            <atom:updated>2026-11-15T05:41:01.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*775SAbewx1sju1DAlGU9LQ.png" /></figure><p>This is Article 15 of 25 in the DevOps Concepts Series (Part 4 of 6: CI/CD &amp; Git Workflows). A pipeline that takes 20 minutes changes how a team works: people batch changes, skip checks and context-switch while they wait. This article starts from a deliberately slow pipeline and speeds it up one step at a time.</p><h4>Key Takeaways</h4><pre>- Measure first: the run summary and per-step timings show where time actually goes.<br> - Cache dependencies and Docker layers so unchanged work is not repeated.<br> - Split independent work into parallel jobs and use a matrix to fan out tests.<br> - Use needs only where order really matters, and skip jobs that are not relevant with if and path filters.<br> - Move repeated logic into reusable workflows so one fix improves every pipeline.<br> - Faster is not always safer: keep security scans and pinned actions even when you tune for speed.</pre><h3>Why does pipeline speed matter?</h3><p>CI time is a feedback loop. A five-minute pipeline lets a developer fix a failure while the code is still in their head. A thirty-minute one gets ignored until later. There is also a direct cost: hosted runner minutes are billed, and slower pipelines occupy concurrency slots that other repositories need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_iQHwcI2fMFSEesoXGTjYA.png" /></figure><h3>Step 0: find the bottleneck</h3><p>Do not guess. Open a workflow run and look at:</p><ul><li>the duration of each job and each step,</li><li>which steps repeat identical work on every run (dependency downloads, image builds),</li><li>which jobs wait on others without needing their output.</li></ul><p>Here is the starting point, a deliberately inefficient pipeline for taskflow:</p><pre>name: CI<br>on: [push, pull_request]</pre><pre>jobs:<br>  everything:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - uses: actions/setup-python@v5<br>        with:<br>          python-version: &quot;3.12&quot;<br>      - run: pip install -r requirements.txt<br>      - run: ruff check .<br>      - run: pytest tests/unit<br>      - run: pytest tests/integration<br>      - run: docker build -t taskflow:ci .<br>      - run: docker run --rm taskflow:ci python -c &quot;import app&quot;</pre><p>One job, everything sequential, no caching, an image built from scratch on every push. Suppose the timings show roughly: install 90 seconds, lint 20, unit tests 60, integration tests 180, Docker build 240. Everything adds up because nothing overlaps.</p><h3>Optimization 1: cache dependencies</h3><p>Dependency installation repeats identical downloads when requirements.txt has not changed. The setup actions can cache for you:</p><pre>- uses: actions/setup-python@v5<br>  with:<br>    python-version: &quot;3.12&quot;<br>    cache: pip</pre><p>The cache key is derived from the dependency file hash. Change the file and a new cache is created. For anything the built-in support does not cover, use actions/cache with an explicit key:</p><pre>- uses: actions/cache@v4<br>  with:<br>    path: ~/.cache/pre-commit<br>    key: pre-commit-${{ hashFiles(&#39;.pre-commit-config.yaml&#39;) }}</pre><p>Caches are scoped to branches: a pull request can read the cache of its base branch, but not the reverse. Entries unused for a while are evicted and total size per repository is limited, so cache what is slow to produce, not everything.</p><h3>Optimization 2: parallel jobs</h3><p>Lint, unit tests, integration tests and the image build do not depend on each other. Split them:</p><pre>jobs:<br>  lint:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - uses: actions/setup-python@v5<br>        with: { python-version: &quot;3.12&quot;, cache: pip }<br>      - run: pip install ruff<br>      - run: ruff check .</pre><pre>  unit:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - uses: actions/setup-python@v5<br>        with: { python-version: &quot;3.12&quot;, cache: pip }<br>      - run: pip install -r requirements.txt<br>      - run: pytest tests/unit</pre><pre>  integration:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - uses: actions/setup-python@v5<br>        with: { python-version: &quot;3.12&quot;, cache: pip }<br>      - run: pip install -r requirements.txt<br>      - run: pytest tests/integration</pre><p>Wall-clock time is now the slowest job, not the sum. The trade-off is that each job repeats checkout and setup, which is why caching in the previous step matters.</p><h3>Optimization 3: matrix strategies</h3><p>When the same job must run across variations, a matrix generates the jobs. It also lets you shard a slow test suite:</p><pre>integration:<br>  runs-on: ubuntu-latest<br>  strategy:<br>    fail-fast: false<br>    matrix:<br>      shard: [1, 2, 3]<br>  steps:<br>    - uses: actions/checkout@v4<br>    - uses: actions/setup-python@v5<br>      with: { python-version: &quot;3.12&quot;, cache: pip }<br>    - run: pip install -r requirements.txt pytest-split<br>    - run: pytest tests/integration --splits 3 --group ${{ matrix.shard }}</pre><p>Three runners each take about a third of the 180 seconds. fail-fast: false lets the other shards finish so you see every failure, not just the first. Remember that more runners mean more billed minutes in total even though the wall-clock time drops.</p><h3>Optimization 4: Docker build caching with BuildKit</h3><p>Building the image from scratch on every run is usually the largest cost. The GitHub Actions cache backend for BuildKit stores layers between runs:</p><pre>build:<br>  needs: [lint, unit]<br>  runs-on: ubuntu-latest<br>  steps:<br>    - uses: actions/checkout@v4<br>    - uses: docker/setup-buildx-action@v3<br>    - uses: docker/build-push-action@v6<br>      with:<br>        context: .<br>        push: false<br>        tags: taskflow:ci<br>        cache-from: type=gha<br>        cache-to: type=gha,mode=max</pre><p>cache-from reads previous layers, cache-to writes them, and mode=max also stores intermediate stages of multi-stage builds. This works together with the layer ordering from Article 11: copy dependency files first so that code-only changes reuse the install layer.</p><h3>Optimization 5: conditional execution and path filters</h3><p>Not every change needs every job. A documentation edit should not rebuild an image.</p><pre>on:<br>  pull_request:<br>    paths-ignore:<br>      - &quot;docs/**&quot;<br>      - &quot;**.md&quot;</pre><p>Inside a workflow, use if to skip work:</p><pre>publish:<br>  if: github.ref == &#39;refs/heads/main&#39; &amp;&amp; github.event_name == &#39;push&#39;</pre><p>Add concurrency to cancel superseded runs when someone pushes again to the same branch:</p><pre>concurrency:<br>  group: ci-${{ github.ref }}<br>  cancel-in-progress: true</pre><p>Only enable cancel-in-progress for CI. Do not use it for deployment workflows where cancelling halfway could leave a release inconsistent.</p><h3>Optimization 6: reusable workflows and job dependencies</h3><p>If ten repositories repeat the same lint and test jobs, any improvement has to be made ten times. Put the pipeline in one place:</p><pre># .github/workflows/python-ci.yml in a shared repository<br>on:<br>  workflow_call:<br>    inputs:<br>      python-version:<br>        type: string<br>        default: &quot;3.12&quot;</pre><p>Callers then use uses: my-org/shared-workflows/.github/workflows/python-ci.yml@v1. Use needs only where order is real, for example build after tests pass. Unnecessary needs edges turn a parallel graph back into a sequence.</p><h3>Artifact optimization</h3><ul><li>Upload only what a later job needs, not the whole workspace.</li><li>Set retention-days to a short value for build output.</li><li>Compress large artifacts, or push images to a registry instead of passing them as files.</li></ul><h3>Runner selection and cost</h3><ul><li>Larger hosted runners finish CPU-heavy work faster but cost more per minute. Compare cost per run, not per minute.</li><li>Self-hosted runners remove per-minute fees and keep warm caches, but you maintain them and must isolate untrusted code, especially from public repositories.</li><li>Linux runners are cheaper than Windows and macOS, so run only what needs those systems on them.</li></ul><h3>The result</h3><p>After the changes the structure looks like this: lint and unit tests run in parallel, integration tests run as three shards, and the image build starts as soon as lint and unit pass, reusing cached layers. With the example timings, the pipeline falls from roughly 590 seconds in sequence to about 4 minutes on a cold cache and noticeably less when caches are warm. Your numbers will differ; the method is what carries over.</p><h3>Security versus performance</h3><p>Speed tricks can weaken safety if applied carelessly.</p><ul><li>Caches are shared within a branch scope. Do not restore a cache in a privileged job that an untrusted pull request could have poisoned.</li><li>Skipping the vulnerability scan on “small” changes defeats its purpose. Run it in parallel instead of dropping it.</li><li>Do not remove pinned action versions or permissions blocks to save a few lines.</li><li>Do not pass secrets to jobs from forked pull requests to enable faster flows.</li></ul><h3>Common mistakes</h3><ul><li>Optimizing without timings, then caching something that was already fast.</li><li>Cache keys that never change, so stale data is served, or change every run, so nothing is ever reused.</li><li>Splitting into many tiny jobs where checkout and setup cost more than the work.</li><li>Using needs between jobs that do not depend on each other.</li><li>Matrix explosions: three OS versions times four Python versions times two databases is 24 jobs on every push.</li></ul><h3>Best practices</h3><ul><li>Order work from cheapest to most expensive and fail fast.</li><li>Keep a baseline of pipeline duration and watch for regressions.</li><li>Cache dependencies and Docker layers; avoid caching build outputs that are cheap to regenerate.</li><li>Use concurrency groups for pull request CI.</li><li>Centralize repeated logic in reusable workflows.</li></ul><h3>Challenge</h3><p>Take a pipeline you own, record the duration of each job, then apply one change from this article. Re-run twice (cold and warm cache) and compare the three timings.</p><h3>Related in this series</h3><ul><li>Previous: DevOps Concepts 14/25 — GitHub Actions Workflow: Understanding CI/CD Automation</li><li>Next: DevOps Concepts 16/25 — GitHub Branching Strategy: Choosing the Right Workflow for Your Team</li><li>Related: DevOps Concepts 11/25 — Docker Cache: Speeding Up Container Builds</li></ul><p>This is Article 15 of 25 in the DevOps Concepts Series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2779520fd2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevOps Concepts 14/25 — GitHub Actions Workflow: Understanding CI/CD Automation]]></title>
            <link>https://medium.com/@anubhavbhatt/devops-concepts-14-25-github-actions-workflow-understanding-ci-cd-automation-5f04e8e7cb10?source=rss-9379711ef44------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f04e8e7cb10</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Anubhav Bhatt]]></dc:creator>
            <pubDate>Sat, 14 Nov 2026 17:14:37 GMT</pubDate>
            <atom:updated>2026-11-14T17:14:37.784Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bgkt_OqLn7wAFneULOu9LQ.png" /></figure><p>This is Article 14 of 25 in the DevOps Concepts Series (Part 4 of 6: CI/CD &amp; Git Workflows). Parts 1 to 3 covered how to provision infrastructure and package apps. This part covers how code gets from a laptop to a registry and a running environment without anyone typing deploy commands by hand.</p><h4>Key Takeaways</h4><pre>- A workflow is a YAML file in .github/workflows/ that runs jobs when an event happens.<br> - Jobs run in parallel on separate runners by default; steps inside a job run in order on one runner.<br> - Use needs to order jobs, and pass files between jobs with artifacts, because each job gets a fresh machine.<br> - Store credentials in secrets and scope them to environments; prefer the built-in GITHUB_TOKEN with minimal permissions.<br> - Pin third-party actions to a version or commit SHA and set permissions explicitly.<br> - Gate deployments with environments and required reviewers instead of manual scripts.</pre><h3>Why do we need CI/CD at all?</h3><p>Without automation, shipping software looks like this: a developer runs tests locally (maybe), builds an image on their laptop, pushes it, and SSHs somewhere to restart a service. Every step depends on one person’s machine and memory.</p><p>Continuous integration (CI) means every change is automatically built and tested when it is pushed. Continuous delivery or deployment (CD) means a change that passes is automatically packaged and released, sometimes after an approval. The result is smaller changes, faster feedback and a release process that is written down as code.</p><p>GitHub Actions is the CI/CD system built into GitHub. The pipeline definition lives in the same repository as the code, so it is reviewed, versioned and branched like everything else.</p><h3>The fundamentals: workflows, events, jobs and steps</h3><p>Four concepts explain almost everything.</p><ul><li><strong>Workflow</strong>: a YAML file in .github/workflows/. A repository can have many.</li><li><strong>Event</strong>: what starts the workflow, such as push, pull_request, schedule or workflow_dispatch.</li><li><strong>Job</strong>: a group of steps that run on one runner. Jobs run in parallel unless you order them with needs.</li><li><strong>Step</strong>: a single task, either a shell command (run) or a reusable action (uses).</li></ul><p>A runner is the machine that executes a job. GitHub-hosted runners are fresh virtual machines (Ubuntu, Windows, macOS) created for each job and destroyed afterwards. Self-hosted runners are machines you operate, useful for private network access, special hardware or cost control, but you own their patching and isolation.</p><h3>Architecture overview</h3><p>When you push a commit, this happens:</p><p>1. GitHub receives the push and matches it against the on: triggers of every workflow file.</p><p>2. For each matching workflow it creates a workflow run and queues its jobs.</p><p>3. A runner picks up each job, checks out nothing by default, and executes the steps in order.</p><p>4. Each step reports status and logs back to GitHub. If a step fails, the job stops and later dependent jobs are skipped.</p><p>5. Artifacts, caches and deployment statuses are stored and shown in the pull request or Actions tab.</p><p>The important consequence: jobs do not share a filesystem. If the build job produces something the deploy job needs, you must upload it as an artifact or push it to a registry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Fb8mjpe0qeYCQA_gWdMEw.png" /></figure><h3>How the pipeline for taskflow will work</h3><p>We will build a pipeline for a small Python app called taskflow:</p><p>1. test: install dependencies and run pytest.</p><p>2. build-and-push: build a Docker image and publish it to GitHub Container Registry, only after tests pass and only on the main branch.</p><p>3. deploy: deploy to a staging environment that requires approval.</p><h3>Hands-on implementation</h3><p>Create .github/workflows/ci.yml:</p><pre>name: CI</pre><pre>on:<br>  push:<br>    branches: [main]<br>  pull_request:<br>    branches: [main]<br>  workflow_dispatch:</pre><pre>permissions:<br>  contents: read</pre><pre>env:<br>  IMAGE_NAME: ghcr.io/${{ github.repository }}</pre><pre>jobs:<br>  test:<br>    runs-on: ubuntu-latest<br>    strategy:<br>      matrix:<br>        python-version: [&quot;3.11&quot;, &quot;3.12&quot;]<br>    steps:<br>      - uses: actions/checkout@v4</pre><pre>      - uses: actions/setup-python@v5<br>        with:<br>          python-version: ${{ matrix.python-version }}<br>          cache: pip</pre><pre>      - name: Install dependencies<br>        run: pip install -r requirements.txt</pre><pre>      - name: Run tests<br>        run: pytest --junitxml=report.xml</pre><pre>      - name: Upload test report<br>        if: always()<br>        uses: actions/upload-artifact@v4<br>        with:<br>          name: test-report-${{ matrix.python-version }}<br>          path: report.xml</pre><pre>  build-and-push:<br>    needs: test<br>    if: github.ref == &#39;refs/heads/main&#39; &amp;&amp; github.event_name == &#39;push&#39;<br>    runs-on: ubuntu-latest<br>    permissions:<br>      contents: read<br>      packages: write<br>    steps:<br>      - uses: actions/checkout@v4</pre><pre>      - uses: docker/setup-buildx-action@v3</pre><pre>      - uses: docker/login-action@v3<br>        with:<br>          registry: ghcr.io<br>          username: ${{ github.actor }}<br>          password: ${{ secrets.GITHUB_TOKEN }}</pre><pre>      - name: Build and push<br>        uses: docker/build-push-action@v6<br>        with:<br>          context: .<br>          push: true<br>          tags: |<br>            ${{ env.IMAGE_NAME }}:${{ github.sha }}<br>            ${{ env.IMAGE_NAME }}:latest</pre><pre>  deploy-staging:<br>    needs: build-and-push<br>    runs-on: ubuntu-latest<br>    environment: staging<br>    steps:<br>      - name: Deploy<br>        run: |<br>          echo &quot;Deploying ${{ env.IMAGE_NAME }}:${{ github.sha }} to staging&quot;<br>          # replace with kubectl, helm or a call to your deploy tool</pre><h3>Configuration breakdown</h3><ul><li>on: lists the triggers. push and pull_request cover the normal flow, schedule takes a cron expression for nightly jobs, and workflow_dispatch adds a manual &quot;Run workflow&quot; button.</li><li>permissions: limits what the automatic GITHUB_TOKEN can do. Setting contents: read at the top and granting packages: write only to the job that pushes follows least privilege.</li><li>env: at the workflow level defines variables for all jobs. You can also set env per job or per step.</li><li>strategy.matrix expands one job into several, here one per Python version.</li><li>cache: pip in setup-python stores downloaded packages between runs.</li><li>needs: test makes the build job wait for every matrix leg of test to succeed.</li><li>if: conditions skip a job. Pull requests run tests but never publish an image.</li><li>secrets.GITHUB_TOKEN is created per run and expires when it ends. Use it for GHCR instead of a long-lived personal token.</li><li>environment: staging links the job to a deployment environment. In repository settings you can add required reviewers, a wait timer and environment-specific secrets. The job pauses until approval.</li><li>upload-artifact stores files after the job, which is also how you hand build output to a later job with download-artifact.</li></ul><h3>Reusable actions and reusable workflows</h3><p>uses: owner/repo@version pulls an action, which is a packaged step. For logic you repeat across repositories, a reusable workflow is better. It is a workflow with on: workflow_call that other workflows invoke:</p><pre>jobs:<br>  call-tests:<br>    uses: my-org/shared-workflows/.github/workflows/python-test.yml@v1<br>    with:<br>      python-version: &quot;3.12&quot;<br>    secrets: inherit</pre><p>Use actions for single steps and reusable workflows for whole jobs or pipelines.</p><h3>Secrets and variables</h3><ul><li><strong>Secrets</strong> are encrypted and masked in logs. Define them at repository, environment or organization level.</li><li><strong>Variables</strong> (vars.NAME) hold non-sensitive configuration.</li><li>Secrets are not passed to workflows triggered from forks on pull_request, which protects you from untrusted code reading them.</li></ul><p>Reference them with ${{ secrets.NAME }} and never echo them or build them into an image layer.</p><h3>Real-world use cases</h3><ul><li>Running tests and linting on every pull request, with the result as a required status check.</li><li>Building and publishing container images tagged with the commit SHA.</li><li>Nightly scheduled jobs for dependency audits or integration tests.</li><li>Manual workflow_dispatch runs for rollbacks or one-off maintenance.</li><li>Deploying to staging automatically and to production after a reviewer approves.</li></ul><h3>Common mistakes</h3><ul><li><strong>Expecting files to persist between jobs.</strong> Each job starts on a clean runner. Use artifacts or a registry.</li><li><strong>Forgetting </strong><strong>actions/checkout.</strong> The runner starts with an empty workspace.</li><li><strong>Using </strong><strong>@main or a moving tag for third-party actions.</strong> A compromised or changed action runs in your pipeline. Pin to a release tag or, for high-trust jobs, a full commit SHA.</li><li><strong>Granting broad token permissions.</strong> The default can be wider than needed. Declare permissions explicitly.</li><li><strong>Printing secrets or passing them on the command line.</strong> Masking helps but is not a guarantee. Pass them through env.</li><li><strong>Publishing from pull requests.</strong> Guard push and deploy steps with if conditions on the branch and event.</li><li><strong>Debugging by pushing blindly.</strong> Read the step logs, add workflow_dispatch, and consider running workflows locally with a tool such as act for quick iteration.</li></ul><h3>Best practices</h3><ul><li>Keep one workflow per concern (CI, release, scheduled maintenance) and make jobs small.</li><li>Fail fast: run cheap checks like linting before slow ones.</li><li>Tag images with the commit SHA and treat latest as a convenience only.</li><li>Require the CI job as a status check in branch protection.</li><li>Use environments with required reviewers for production.</li><li>Set timeout-minutes on jobs so a hung step does not burn minutes.</li></ul><h3>Challenge</h3><p>Add a lint job that runs ruff check . and make test depend on it with needs. Then open a pull request with a deliberate lint error and confirm the pipeline stops before the tests run.</p><h3>Related in this series</h3><ul><li>Previous: DevOps Concepts 13/25 — Docker Scout: Identifying Vulnerabilities in Container Images</li><li>Next: DevOps Concepts 15/25 — GitHub Actions Optimization: Building Faster and More Efficient Pipelines</li><li>Related: DevOps Concepts 16/25 — GitHub Branching Strategy: Choosing the Right Workflow for Your Team</li></ul><p>This is Article 14 of 25 in the DevOps Concepts Series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f04e8e7cb10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A2UI 1.0: Google’s Protocol for Agent-Generated Native UI]]></title>
            <link>https://medium.com/@anubhavbhatt/a2ui-1-0-googles-protocol-for-agent-generated-native-ui-3d35f778b789?source=rss-9379711ef44------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d35f778b789</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <dc:creator><![CDATA[Anubhav Bhatt]]></dc:creator>
            <pubDate>Thu, 12 Nov 2026 11:57:03 GMT</pubDate>
            <atom:updated>2026-11-12T11:57:03.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4T1FkXXhlfO5hTRWAPAC_A.png" /><figcaption>A2UI 1.0: Google’s Protocol for Agent-Generated Native UI</figcaption></figure><p>Many AI agents still answer in text, even when a form, chart or approval button would serve the user better. On November 11, 2026, Google <a href="https://developers.googleblog.com/a2ui-10-build-delightful-fast-reliable-agentic-experiences/">released A2UI 1.0</a>, which it calls “the first stable version of our open protocol for generative UI.” An agent describes the interface it wants, and the host app renders it with its own native components.</p><h3>Key Takeaways</h3><pre>- A2UI is an open protocol: the agent describes the UI, the app decides how to render it.<br> - Agents stream declarative JSON with two-way bindings, never executable code, and can place only components the app has registered.<br> - 1.0 adds bidirectional function calls, accessibility support and extensions for extra metadata.<br> - Renderers exist for React, Angular, Lit, Flutter, SwiftUI and Jetpack Compose; agent SDKs cover Python, TypeScript and Dart.<br> - Not every piece is at 1.0 yet: Jetpack Compose is at v0.9.1, and Gemini supports A2UI 0.9.1 today.<br> - The web and Flutter renderers also work inside MCP Apps (an extension that lets assistants show interactive UI), so A2UI screens can appear in assistants such as Claude and Gemini.<br> - Treat actions from a generated interface as untrusted input; validation and authorization stay on the server.</pre><h3>Why is text a poor interface for agents?</h3><p>A typical agent loop is: the user asks, the agent answers in text, the user replies. That works for explanations and summaries. It gets slow when the user must decide something.</p><p>Take “reschedule my meetings, book a video consultation and notify my team.” A text agent returns a list of suggestions, then asks follow-up questions one message at a time. One screen with a reschedule panel, a booking form, a notification preview and a confirm button would finish the job in a single pass.</p><p>That is the idea behind generative UI: the agent picks the interface that fits the task instead of forcing everything through chat. For a hands-on look at AI-generated React interfaces, see <a href="https://daily.dev/blog/ai-native-ui-development">AI-Assisted React UI: Validate Every Component</a>.</p><h3>What is A2UI?</h3><p>According to <a href="https://a2ui.org/">a2ui.org</a>, A2UI is “an open-source generative UI framework that enables agents to select, compose, or build experiences that are personalized in the moment, native to your brand, and secure.” It combines an agent-optimized protocol, native renderers and SDKs for agent frameworks.</p><p>The split of responsibility is the key point:</p><ul><li><strong>Agent:</strong> understands intent and decides which interface to show.</li><li><strong>Host app:</strong> receives the description, validates it and renders it with its own components and design system.</li></ul><p>An agent might ask for a form, a chart, a product card, a confirmation dialog or a comparison view. It does not send HTML. The same description can render in React on the web, SwiftUI on iOS or Jetpack Compose on Android.</p><h3>How an A2UI flow works</h3><p>The project’s README describes three layers:</p><ol><li><strong>Inference.</strong> The agent generates a description of the UI and its data in an inference format, such as A2UI Express or a decision tree.</li><li><strong>Transport.</strong> The agent SDK parses and validates the model’s output, expands macros, and converts the UI into A2UI transport protocol messages.</li><li><strong>Rendering.</strong> A renderer, made of a core library, a framework adapter and a widget catalog, turns the messages into native components.</li></ol><p>In practice: the user asks the agent to compare three products. The agent retrieves the data and decides a comparison view fits. The SDK emits A2UI messages. The app maps them to its registered components, such as product cards and a highlighted recommendation. When the user changes a preference, the interface can call back to the agent, which returns updated data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Z2mOglG6S27AK8Ir" /></figure><h3>Why not let the model generate HTML?</h3><p>Generated HTML, CSS and JavaScript is the obvious shortcut, but it brings untrusted code, inconsistent design, accessibility gaps and little control over behavior.</p><p>A2UI takes the opposite route. On <a href="http://a2ui.org/">a2ui.org</a>, the developer registers each widget as a catalog component, and the “locked catalog” means “agents place only components you registered.” The agent streams “declarative JSON data with two-way bindings — never executable code.” The README states the principle as “Security first: The app developer controls what the agent can and cannot do in the app.”</p><p>Google also says A2UI “reliably binds to your data and child components on the server, so sensitive values never reach the model.”</p><p>A company might register ProductCard, PricingTable, ApprovalForm and AnalyticsChart. The agent composes with those and nothing else.</p><h3>What 1.0 adds</h3><p>The <a href="https://developers.googleblog.com/a2ui-10-build-delightful-fast-reliable-agentic-experiences/">announcement</a> lists three groups of changes.</p><h3>A stable protocol</h3><p>Version 1.0 adds bidirectional function calls, so a flight or reservation picker can check availability on the spot. The protocol also adds accessibility support and extensions for additional metadata.</p><h3>Renderers for major platforms</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*mKTOl3VzDflutSNd" /></figure><p>The web and Flutter renderers also work inside MCP Apps. Jetpack Compose is currently at v0.9.1, with v1.0 coming soon, according to <a href="https://developers.googleblog.com/a2ui-10-build-delightful-fast-reliable-agentic-experiences/">Google</a>.</p><h3>Agent SDKs and faster generation</h3><p>SDKs exist for Python, TypeScript and Dart. They help with generating skills, translating messages and correcting errors. Swappable inference formats reduce latency, and in Python, A2UI Macros add programmatic component expansion and data binding.</p><p>To cut generation time, Google points to A2UI Express and “system one” decision models, which pick components and values instead of writing text.</p><h3>How does A2UI compare with generated HTML?</h3><p><a href="http://a2ui.org/">a2ui.org</a> places A2UI on a “generative UI spectrum” with three points:</p><ul><li><strong>Pre-built widgets:</strong> you register each widget as a catalog component or a server-side macro.</li><li><strong>Composed screens:</strong> the agent assembles screens from your native catalog. This is A2UI’s target.</li><li><strong>Generated HTML/JS in a sandbox:</strong> the most flexible option, and the one with the most security and consistency work to do.</li></ul><p>A2UI sits in the middle: more flexible than fixed widgets, with a locked catalog instead of arbitrary code.</p><h3>Who is building with A2UI?</h3><ul><li><strong>Atlassian</strong> (planned, per Google) is bringing A2UI to Jira, where teams can assign work items to AI agents. An agent that needs a follow-up asks with an interactive card in the work item.</li><li><strong>Alation</strong> builds feeds in its Intelligence Operating System (AIOS) using A2UI: metric cards, charts and more. The feeds render in Claude and in Alation’s Data Products App.</li><li><strong>ByteDance</strong> released an A2UI renderer for its Lynx cross-platform framework in June 2026. Lynx supports A2UI 0.9 today and is adapting to 1.0 with the A2UI team.</li><li><strong>Gemini Notebook</strong> replies to a slide deck request with a card for choosing format and focus. The same cards guide Video Overviews on web and mobile.</li></ul><p><a href="https://developers.googleblog.com/a2ui-10-build-delightful-fast-reliable-agentic-experiences/">Google also names</a> Bloomberg among the companies building with A2UI, and says Gemini supports A2UI 0.9.1 today, with organizations able to register their own A2UI agents.</p><h3>A2UI and MCP Apps</h3><p>They solve different problems. <a href="https://modelcontextprotocol.io/">MCP</a> is the Model Context Protocol for connecting assistants to tools and data. MCP Apps is its extension for showing interactive interfaces inside supporting assistants; Google names Claude and Gemini as examples. For MCP-based workflows, see <a href="https://daily.dev/blog/ai-workflow-automation-n8n-mcp">AI Workflow Automation with n8n and MCP</a>.</p><p><a href="http://a2ui.org/">a2ui.org</a> says that in hosts that support MCP Apps, the same A2UI surface can run inside an MCP App. It also describes the reverse: generated HTML and JavaScript can run as an MCP App inside an A2UI surface, next to native components. A2UI itself carries declarative data; an MCP App is a separate layer that hosts web content.</p><p>For a project assistant: MCP connects to the tracker, the agent gathers tasks, A2UI describes a dashboard with task cards and approval controls, and the MCP Apps host displays it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*V6VTcVnJTXgub_XV" /></figure><h3>Getting started</h3><ul><li>Read the protocol and v1.0 specification at <a href="https://a2ui.org/">a2ui.org</a>.</li><li>Run the <a href="https://a2ui.org/quickstart/">quickstart</a> or try the <a href="https://go.copilotkit.ai/a2ui-playground">CopilotKit A2UI Playground</a>.</li><li>Pick a renderer: @a2ui/react, @a2ui/angular, @a2ui/lit (npm), a2ui_flutter on pub.dev, or the SwiftUI and Jetpack Compose renderers.</li><li>Add an agent SDK: a2ui-agent-sdk for Python on PyPI, or @a2ui/agent for TypeScript on npm.</li><li>If you already build MCP Apps, try hosting an A2UI surface inside one.</li><li>Repository: <a href="https://github.com/google/A2UI">github.com/google/A2UI</a>.</li></ul><h3>What still needs engineering care</h3><p>A2UI constrains what an agent can render, but it does not replace the rest of the stack. Component permissions, data access, authorization, accessibility, error handling and confirmation steps for risky actions remain your job. Treat every action coming back from a generated interface as untrusted input and validate it on the server.</p><h3>Conclusion</h3><p>A2UI 1.0 gives agents a standard way to say what the user should see while apps keep control of rendering, behavior and design. With native renderers across web and mobile, agent SDKs in three languages and a path into MCP Apps, it is a concrete option for teams building agent experiences that go beyond chat.</p><h3>References</h3><ul><li><a href="https://developers.googleblog.com/a2ui-10-build-delightful-fast-reliable-agentic-experiences/">A2UI 1.0: Build delightful, fast, reliable, agentic experiences</a> (Google Developers Blog, Nov 11, 2026)</li><li><a href="https://a2ui.org/">A2UI website</a></li><li><a href="https://github.com/google/A2UI">A2UI on GitHub</a></li><li><a href="https://modelcontextprotocol.io/">Model Context Protocol</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d35f778b789" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevOps Concepts 13/25 — Docker Scout: Identifying Vulnerabilities in Container Images]]></title>
            <link>https://medium.com/@anubhavbhatt/devops-concepts-13-25-docker-scout-identifying-vulnerabilities-in-container-images-140eb526b51f?source=rss-9379711ef44------2</link>
            <guid isPermaLink="false">https://medium.com/p/140eb526b51f</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-scout]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[vulnerability]]></category>
            <dc:creator><![CDATA[Anubhav Bhatt]]></dc:creator>
            <pubDate>Thu, 12 Nov 2026 05:41:01 GMT</pubDate>
            <atom:updated>2026-11-12T05:41:01.617Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_fg1Mm2-MbI6ghi3D1mMrw.png" /><figcaption>DevOps Concepts — Docker Scout: Identifying Vulnerabilities in Container Images</figcaption></figure><p>This is Article 13 of 25 in the DevOps Concepts Series (Part 3 of 6: Docker Deep Dive). An image contains your code and hundreds of packages you did not write. Docker Scout tells you which of them have known vulnerabilities and what to change.</p><h3>Key Takeaways</h3><pre>- Most of an image&#39;s vulnerabilities come from the base image and dependencies, not your own code.<br> - A CVE is a public identifier for a known vulnerability; severity does not equal exploitability in your context.<br> - An SBOM lists every package in an image, which lets tools match them against vulnerability databases.<br> - docker scout quickview, cves and recommendations take you from overview to a specific fix.<br> - Updating the base image often removes more findings than patching individual packages.<br> - Run scanning in CI and fail the build on new critical or high findings with a fix available.</pre><h3>Why does image security matter?</h3><p>A container image bundles an operating system userland, a language runtime, third-party libraries and your code. Each of those is software with its own bugs. When a vulnerability is published, every image that contains the affected package becomes exposed, including ones built months ago and never rebuilt.</p><p>Common sources of vulnerabilities in images:</p><ul><li>An outdated or bloated base image with packages your app never uses.</li><li>Old Python dependencies pinned years ago.</li><li>Build tools left in the final image.</li><li>Packages installed from unverified sources.</li></ul><p>Supply chain security extends this: you need to know what is inside the images you run and where each component came from.</p><h3>What are CVEs and SBOMs?</h3><p>A CVE (Common Vulnerabilities and Exposures) entry is a public identifier such as CVE-YYYY-NNNNN for one known vulnerability. Each is scored by severity: low, medium, high or critical. A high score means the issue could be serious in some setting, not that your app is definitely exploitable. Whether a vulnerable library is reachable depends on how you use it.</p><p>An SBOM (Software Bill of Materials) is an inventory of the packages inside an image, with versions. It is the input that scanners match against vulnerability databases. SBOMs also help when a new vulnerability is announced: you search your inventory instead of scanning from scratch.</p><h3>What is Docker Scout?</h3><p>Docker Scout analyzes an image, builds its SBOM, compares each component with vulnerability data, and reports findings per package and per layer. It also suggests base image updates and shows how an image differs from another. It is available through the Docker CLI as docker scout, in Docker Desktop and on Docker Hub, with features that depend on your Docker plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L_QU8PBVAoZ8MnEP2egLig.png" /><figcaption>Image layers scanned by Docker Scout, producing CVE findings, an SBOM and a fixed image through a CI pipeline</figcaption></figure><h3>Hands-on: scanning a Python image</h3><p>Start with an image that is deliberately out of date, such as an old base and an old dependency:</p><pre>FROM python:3.9<br>WORKDIR /srv<br>COPY requirements.txt .<br>RUN pip install -r requirements.txt<br>COPY app ./app<br>CMD [&quot;uvicorn&quot;, &quot;app.main:app&quot;, &quot;--host&quot;, &quot;0.0.0.0&quot;, &quot;--port&quot;, &quot;8000&quot;]</pre><pre>docker build -t taskflow:scan .<br>docker login</pre><p>Get an overview:</p><pre>docker scout quickview taskflow:scan</pre><p>The quick view summarizes counts of critical, high, medium and low findings for the image and its base image, and tells you whether a newer base would reduce them.</p><p>List the findings:</p><pre>docker scout cves taskflow:scan<br>docker scout cves --only-severity critical,high taskflow:scan<br>docker scout cves --only-fixed taskflow:scan</pre><p>--only-fixed hides vulnerabilities that have no fixed version yet, which is useful for deciding what you can act on today. Each result shows the affected package, its installed version, the fixed version if one exists, and the layer that introduced it.</p><p>Export the SBOM:</p><pre>docker scout sbom taskflow:scan<br>docker scout sbom --format spdx taskflow:scan &gt; taskflow.spdx.json</pre><p>Ask for recommendations:</p><pre>docker scout recommendations taskflow:scan</pre><p>This suggests newer or smaller base images and shows how many findings each option would remove.</p><h3>Fixing the findings</h3><p>Work from the biggest lever to the smallest.</p><ol><li>Update the base image. Moving from a full, old image to a current slim one usually removes most findings at once.</li></ol><pre>FROM python:3.12-slim</pre><p>2. Update vulnerable Python dependencies to the fixed versions that Scout reports, then rerun your tests.</p><pre># requirements.txt: bump the package listed under &quot;fixed versio</pre><p>3. Remove what you do not need. A multi-stage build (Article 10) leaves compilers and build tooling behind.</p><p>4. Rebuild and compare:</p><pre>docker build -t taskflow:fixed .<br>docker scout compare --to taskflow:scan taskflow:fixed<br>docker scout quickview taskflow:fixed</pre><p>docker scout compare shows which vulnerabilities disappeared and whether any new ones appeared.</p><p>Some findings will remain with no fix available. Decide whether the vulnerable code path is reachable, track the issue, and recheck regularly. Avoid suppressing findings without a recorded reason.</p><h3>Integrating Docker Scout into GitHub Actions</h3><p>Run the scan after building the image so every pull request gets feedback. Docker publishes an action for this:</p><pre>name: build-and-scan<br>on:<br>  pull_request:<br>  push:<br>    branches: [main]</pre><pre>jobs:<br>  scan:<br>    runs-on: ubuntu-latest<br>    permissions:<br>      contents: read<br>      pull-requests: write<br>    steps:<br>      - uses: actions/checkout@v4</pre><pre>      - uses: docker/setup-buildx-action@v3</pre><pre>      - uses: docker/login-action@v3<br>        with:<br>          username: ${{ vars.DOCKERHUB_USERNAME }}<br>          password: ${{ secrets.DOCKERHUB_TOKEN }}</pre><pre>      - uses: docker/build-push-action@v6<br>        with:<br>          context: .<br>          load: true<br>          tags: taskflow:${{ github.sha }}</pre><pre>      - name: Scan for vulnerabilities<br>        uses: docker/scout-action@v1<br>        with:<br>          command: cves<br>          image: taskflow:${{ github.sha }}<br>          only-severities: critical,high<br>          only-fixed: true<br>          exit-code: true</pre><p>What the options do:</p><ul><li>load: true loads the built image into the runner&#39;s local Docker so the next step can scan it without pushing.</li><li>command: cves runs the vulnerability analysis.</li><li>only-severities: critical,high limits the report and the failure condition to the serious levels.</li><li>only-fixed: true ignores issues that cannot be fixed yet, so the pipeline does not block on things nobody can resolve.</li><li>exit-code: true fails the step when matching vulnerabilities are found.</li></ul><p>The login credentials come from repository secrets, never from the workflow file. A scheduled workflow (on: schedule) that rescans the latest released image catches vulnerabilities published after you shipped it.</p><h3>Real-world use cases</h3><ul><li>Gate merges on no new critical or high fixable vulnerabilities.</li><li>Compare a release candidate against the production image before promoting it.</li><li>Answer “are we affected?” within minutes when a new CVE hits a common package.</li><li>Pick a base image by comparing findings across candidates.</li></ul><h3>Common mistakes</h3><ul><li>Treating the severity number as risk without checking reachability.</li><li>Scanning once at release and never again.</li><li>Failing builds on unfixable findings, which teaches the team to ignore the check.</li><li>Upgrading dependencies without running tests.</li><li>Pinning a base image forever and never rebuilding.</li><li>Scanning only the final image and missing that an old base is the main source.</li></ul><h3>Best practices</h3><ul><li>Use small, maintained base images and rebuild them on a schedule.</li><li>Generate and store an SBOM for each released image.</li><li>Fail CI on critical and high findings that have a fix.</li><li>Rescan deployed images periodically.</li><li>Track exceptions with an owner and an expiry date.</li><li>Combine scanning with signing and provenance for stronger supply chain guarantees.</li></ul><h3>Challenge</h3><p>Scan the python:3.9 based image and the python:3.12-slim one, then use docker scout compare to count how many critical and high findings the upgrade removed. Add the GitHub Actions scan job to a repository and open a pull request that bumps one dependency to see the check respond.</p><h3>Related in this series</h3><ul><li>Previous: DevOps Concepts 12/25 — Docker Stats: Monitoring Container Resource Usage</li><li>Next: DevOps Concepts 14/25 — GitHub Actions Workflow: Understanding CI/CD Automation</li><li>Also see: DevOps Concepts 10/25 — Docker Images: Understanding Layers, Registries, and Image Management</li></ul><p>This is Article 13 of 25 in the DevOps Concepts Series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=140eb526b51f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design Caching 3/3 — Production Caching: Failure Scenarios, Performance and Scaling]]></title>
            <link>https://medium.com/@anubhavbhatt/system-design-caching-3-3-production-caching-failure-scenarios-performance-and-scaling-9317d9e418c5?source=rss-9379711ef44------2</link>
            <guid isPermaLink="false">https://medium.com/p/9317d9e418c5</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Anubhav Bhatt]]></dc:creator>
            <pubDate>Wed, 11 Nov 2026 05:41:01 GMT</pubDate>
            <atom:updated>2026-11-11T05:41:01.634Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8A1LagwPYiJbGJ0NuxujA.png" /><figcaption>System Design Caching — Production Caching: Failure Scenarios, Performance and Scaling</figcaption></figure><p>ot key is a single key with an unusually high request rate. In a flash sale, one product’s key maps to one Redis Cluster slot served by one primary node. That node overloads while other nodes sit mostly idle. Adding nodes does not help, because the key still lives in one place.</p><ol><li><strong>Split the key:</strong> keep several copies with suffixes, such as product:100, product:100:1, product:100:2, and spread reads across them. Reads and updates now have to coordinate across multiple keys.</li><li><strong>Client-side caching:</strong> cache hot data inside application processes. Redis supports client-side caching with invalidation messages that tell clients when tracked keys change. It cuts repeated network requests but adds invalidation and connection-tracking overhead.</li><li><strong>Request coalescing:</strong> concurrent requests for the same key share one database operation. Discord has documented using this to cut duplicate database reads. The trade-off is that those requests share the fate of the one underlying operation.</li></ol><p>Hot keys are routing problems. Real fixes change where requests go or how many are generated.</p><h3>What is a cache expiration storm?</h3><p>If many entries are created around the same time with the same TTL, they expire together. Misses spike, the database gets a burst of requests, and Redis documentation also warns that many simultaneous expirations can affect latency.</p><p>The fix is <strong>TTL jitter</strong>: add a random offset so keys expire over a range, for example a value within a window around 60 minutes, instead of exactly 60 minutes. The database then sees a gradual increase.</p><p>TTL is not just a freshness setting; it is also a capacity and load-management setting. Shortening a TTL raises refresh traffic, and a larger cached payload raises the cost of every refresh.</p><h3>What happens when Redis goes down?</h3><p>A cache outage can turn a healthy application into an overloaded database. If your database normally takes 100,000 requests per second with a cache absorbing most reads, losing the cache moves those reads straight to the database, and the origin can fail even though it was healthy before.</p><p>Three fallback strategies:</p><ol><li><strong>Timeout:</strong> cap how long cache operations can take so threads do not wait forever. It does not remove the load from fallback requests.</li><li><strong>Fall back to the database:</strong> read from the primary store when Redis fails. This only works if the database has spare capacity.</li><li><strong>Circuit breaker:</strong> detect repeated cache failures, stop sending requests to the failing node for a while, control how much fallback traffic reaches the database, and let requests through gradually as the dependency recovers.</li></ol><p>Size and load-test the database for the traffic that survives a cache failure. A cache outage should not automatically become a database outage.</p><h3>Why can a cold cache be worse than losing a cache?</h3><p>A cold cache has no useful entries. After a deployment, restart or failover, requests reach the database while popular keys are rebuilt, and a large number of misses can overload the origin.</p><p>Warming strategies:</p><ul><li>Preload frequently accessed keys before sending full traffic.</li><li>Increase traffic gradually.</li><li>Use a warm cluster to populate a new one.</li><li>Test cache recovery as part of deployments.</li><li>Never switch all traffic to a completely cold cluster at once.</li></ul><p>Large caches can take hours or days to warm. Recovery tools must work without the failed cache, because a recovery process that assumes a warm cache can cause another outage.</p><h3>What are common Redis configuration traps?</h3><ul><li><strong>Eviction policy:</strong> some policies only consider keys that have expiry metadata. With volatile-lru, if no keys have a TTL, Redis finds nothing eligible to evict, so writes can fail with out-of-memory errors while reads keep working.</li><li><strong>Memory fragmentation:</strong> Redis may not return freed memory to the operating system right away, because the allocator keeps it for reuse. Process memory can differ from the logical data size, so plan capacity for peak memory.</li><li><strong>Large values and expensive commands:</strong> Redis runs commands on its main thread, so a long-running command delays everything else. Avoid unbounded commands in production, use pagination and bounded operations, and remember that large values complicate Redis Cluster resharding and increase latency.</li></ul><p>The problem is not only how long a command takes. It is how many other requests it blocks while it runs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*vL905ahy6sa40hYt" /></figure><h3>Why is a cache key a security boundary?</h3><p>An HTTP cache key commonly includes the request method and URI. The response may also depend on authentication state, user identity, language, tenant, request headers and cookies. If those are missing from the cache key, different users can receive the same cached response.</p><ul><li><strong>Vary:</strong> the Vary header lists the request headers that influence the representation. A cache should reuse a response only when those header values match. CDNs may handle them differently, so do not assume default behavior gives you the isolation you need.</li><li><strong>Cache poisoning:</strong> an attacker manipulates inputs that affect the response but are not in the cache key, the cache stores the manipulated response, and other users receive it.</li><li><strong>Web cache deception:</strong> a caching layer treats an authenticated page as a static resource and stores a personalized response under a cacheable-looking URL, and another user may receive sensitive content.</li></ul><p>Prevention: include every response-varying input in the cache key, avoid shared caching of personalized or authenticated responses unless isolation is designed in, review CDN cache-key configuration, validate cookie and authentication behavior, test across users and tenants, and use private and no-store where needed.</p><h3>Is hit rate enough to judge a cache?</h3><p>No. If hits take 1 ms and misses take 100 ms, a 95% hit rate still means 5% of requests pay the miss penalty.</p><pre>average latency = hit time + miss ratio x miss penalty</pre><p>Miss ratio tells you more. A 95% hit rate is a 5% miss ratio and a 99% hit rate is 1%, so at 99% the origin receives five times fewer requests. Also watch the worst miss ratio during peak traffic: averages hide short bursts of high database load, and the database has to survive the traffic the cache fails to absorb.</p><h3>How big should a cache be?</h3><p>Base size on real access patterns. A working set is the unique data accessed within a time window, and a miss ratio curve shows how the miss ratio changes as capacity grows.</p><ul><li>Measure the working set.</li><li>Collect request traces.</li><li>Calculate miss ratios at different cache sizes.</li><li>Find where extra memory stops paying off.</li><li>Account for TTL, since expiry reduces what must stay cached.</li><li>Compare eviction policies, which can produce different hit and miss ratios.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*zE4_jrtvB7ws_mt3" /></figure><h3>Is Redis actually cheaper?</h3><p>Caching is often assumed to be cheaper than database infrastructure. In-memory storage is expensive compared with database disk, and a cache node may be only moderately cheaper per gigabyte than a comparable read replica. A cache earns its cost when the traffic it absorbs justifies it.</p><p>Ask: how many database requests does it remove, what does the database capacity you avoid cost, how much memory does it need, how much traffic does it absorb at peak, and what does it cost to run. Serverless caching has a higher per-gigabyte cost but can make sense for small data volumes, unpredictable or highly variable traffic, or when a permanent cache cluster would be wasteful.</p><h3>When should you not use a cache?</h3><p>Consider skipping or minimizing a cache when:</p><ul><li><strong>There is little repetition:</strong> data requested once gains little.</li><li><strong>Data changes constantly:</strong> you create more invalidation and refresh work.</li><li><strong>Strict consistency is mandatory:</strong> stale data is unacceptable and the cache adds complexity.</li><li><strong>The origin is already fast enough:</strong> the extra layer costs more than the gain.</li></ul><p>Load-test your application with caching disabled and check that the database and application can handle the workload. Never assume the cache is always available.</p><h3>What is sequential flooding?</h3><p>A large sequential scan can touch more data than the cache holds. Under plain LRU, the scanned pages look recent, old popular pages get evicted, and the cache fills with pages unlikely to be read again.</p><p>Databases defend against this. PostgreSQL uses a buffer strategy designed to limit the impact of large scans. MySQL InnoDB uses midpoint insertion: new pages enter the LRU list away from the most protected end, so frequently reused pages are harder to displace. Not every access pattern is cache-friendly, and large scans need special treatment.</p><h3>What should you monitor in production?</h3><ul><li><strong>Hit and miss ratio:</strong> how much traffic the cache absorbs.</li><li><strong>Eviction rate:</strong> how often entries are removed.</li><li><strong>Memory usage:</strong> how close you are to the configured limit.</li><li><strong>Memory fragmentation:</strong> use allocator-level metrics rather than one fragmentation number.</li><li><strong>Connections:</strong> watch counts and unexpected growth.</li><li><strong>CPU:</strong> high eviction rates and expensive commands raise it.</li><li><strong>Network throughput:</strong> bandwidth and request/response volume.</li><li><strong>Origin load:</strong> how much traffic reaches the database.</li><li><strong>Latency:</strong> response times and tail latency.</li></ul><p>A practical checklist:</p><ul><li>Configure an appropriate eviction policy.</li><li>Set TTLs from freshness requirements, with jitter where synchronized expiry is a risk.</li><li>Prevent stampedes.</li><li>Use negative caching where it fits.</li><li>Identify and mitigate hot keys.</li><li>Configure timeouts and circuit breakers.</li><li>Test cache outages and cold-cache recovery.</li><li>Review cache-key security.</li><li>Monitor origin traffic and miss ratios.</li><li>Load-test with caching disabled.</li></ul><h3>Conclusion</h3><p>Prefer reliable invalidation to blind updates. Give the origin a controlled fallback for when the cache disappears. When one key gets popular, change the routing or spread the load. When everything expires together, use jitter and early refresh. When the cache starts empty, warm it gradually. When it gets expensive, measure the traffic it really absorbs. And treat cache keys as part of your authorization and data-isolation design.</p><p>The most important test is simple: run your application with the cache disabled and see what happens to your database. A cache should improve your system, not be the only reason it works.</p><p>Series: System Design Caching Series, Part 3 of 3.</p><p><strong>Previous: Part 2: Distributed Caching: Cache Patterns, Consistency and Sharding.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9317d9e418c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevOps Concepts 12/25 — Docker Stats: Monitoring Container Resource Usage]]></title>
            <link>https://medium.com/@anubhavbhatt/devops-concepts-12-25-docker-stats-monitoring-container-resource-usage-98628f94015c?source=rss-9379711ef44------2</link>
            <guid isPermaLink="false">https://medium.com/p/98628f94015c</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Anubhav Bhatt]]></dc:creator>
            <pubDate>Tue, 10 Nov 2026 23:36:01 GMT</pubDate>
            <atom:updated>2026-11-10T23:36:01.467Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EH9MNcFSMAi_czBcN2097w.png" /><figcaption>DevOps Concepts — Docker Stats: Monitoring Container Resource Usage</figcaption></figure><p>This is Article 12 of 25 in the DevOps Concepts Series (Part 3 of 6: Docker Deep Dive). Containers share a host, so one runaway container can slow everything else. docker stats is the quickest way to see who is using what.</p><h3>Key Takeaways</h3><pre>- docker stats streams live CPU, memory, network, block I/O and process counts for running containers.<br> - CPU % is relative to one core, so a container can show more than 100% on a multi-core host.<br> - MEM USAGE / LIMIT shows the cgroup limit; without --memory the limit is the host&#39;s memory.<br> - A container that exceeds its memory limit is killed by the kernel; docker inspect shows OOMKilled.<br> - Steadily climbing memory with flat traffic suggests a leak.<br> - docker stats is a point-in-time tool; use Prometheus and Grafana for history, alerts and many hosts.</pre><h3>Why does container monitoring matter?</h3><p>Containers are isolated processes, but they compete for the same CPU, memory, disk and network. Without limits and visibility, one container with a memory leak can push the host into swapping or get other containers killed. You need to know what normal looks like for each service before you can spot a problem.</p><h3>What does docker stats show?</h3><p>Run it with no arguments to see all running containers, updated every second:</p><pre>docker stats</pre><p>Typical output columns:</p><ul><li>CONTAINER ID and NAME: which container the line describes.</li><li>CPU %: CPU time used by the container as a percentage of one CPU core, sampled between updates. On a four-core host a container using all cores can show up to 400%.</li><li>MEM USAGE / LIMIT: memory the container is using and the limit it runs under. If you set no limit, the number after the slash is the host&#39;s total memory.</li><li>MEM %: usage divided by limit.</li><li>NET I/O: total bytes received and sent over the container&#39;s network interfaces since it started.</li><li>BLOCK I/O: total bytes read from and written to block devices since it started.</li><li>PIDS: number of processes and threads in the container.</li></ul><p>Useful options:</p><pre>docker stats --no-stream                       # print once and exit<br>docker stats --no-stream web db                # only selected containers<br>docker stats --format &quot;table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}&quot;<br>docker stats --format json --no-stream         # machine-readable</pre><p>Memory usage reported by Docker generally excludes the page cache in recent versions, so it is closer to what the application actually holds. Numbers can differ slightly between Docker versions and cgroup versions, so compare containers on the same host rather than comparing across machines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wbLYPi01XR3JLd5_D2T-ag.png" /><figcaption>Docker host with three containers feeding a stats dashboard of CPU, memory, network and block I/O panels</figcaption></figure><h3>Hands-on: creating load and watching it</h3><p>Start a few containers with different behaviors. Use --cpus and --memory to set resource constraints, which Docker enforces through cgroups.</p><p>CPU-hungry container limited to half a core:</p><pre>docker run -d --name cpu-hog --cpus 0.5 alpine sh -c &#39;while :; do :; done&#39;</pre><p>Memory-growing container limited to 128 MB:</p><pre>docker run -d --name mem-hog --memory 128m python:3.12-slim \<br>  python -c &quot;<br>import time<br>data = []<br>while True:<br>    data.append(b&#39;x&#39; * 1024 * 1024)<br>    time.sleep(0.5)<br>&quot;</pre><p>Network-active container:</p><pre>docker run -d --name net-client alpine sh -c \<br>  &#39;while :; do wget -q -O /dev/null https://example.com; sleep 1; done&#39;</pre><p>Disk-writing container:</p><pre>docker run -d --name disk-writer alpine sh -c \<br>  &#39;while :; do dd if=/dev/zero of=/tmp/file bs=1M count=50 oflag=direct; rm /tmp/file; done&#39;</pre><p>Plus an idle baseline:</p><pre>docker run -d --name idle alpine sleep 3600</pre><p>Now watch them:</p><pre>docker stats</pre><h3>Interpreting the numbers</h3><ul><li>cpu-hog sits near 50% because of --cpus 0.5. Without the limit it would approach 100% of one core. The limit is enforced by CPU throttling, not by killing the process.</li><li>mem-hog climbs by about 2 MB per second until it reaches 128 MB. At the limit the kernel&#39;s out-of-memory killer terminates the process. Confirm with:</li></ul><pre>docker ps -a --filter name=mem-hog<br>docker inspect mem-hog --format &#39;{{.State.OOMKilled}} {{.State.ExitCode}}&#39;</pre><p>true and exit code 137 mean the container was killed for exceeding its memory limit.</p><ul><li>net-client shows NET I/O rising in both columns as it downloads and sends requests.</li><li>disk-writer shows BLOCK I/O writes growing quickly. Large block I/O on a container that should be quiet is worth investigating.</li><li>idle stays close to zero CPU and a few hundred KB of memory, which is your baseline.</li></ul><p>Look at what runs inside a container:</p><pre>docker top mem-hog<br>docker exec mem-hog ps aux</pre><p>Clean up:</p><pre>docker rm -f cpu-hog mem-hog net-client disk-writer idle</pre><h3>Diagnosing common problems</h3><p>High CPU:</p><ul><li>Check CPU % across containers to find the heavy one.</li><li>Use docker top &lt;name&gt; to see which process inside it is responsible.</li><li>If the container is pinned at its --cpus limit and latency is high, it is being throttled; raise the limit or optimize the code.</li></ul><p>Memory leak:</p><ul><li>Watch MEM USAGE over several minutes under constant load. A steady upward slope that never falls back suggests a leak.</li><li>A container that restarts periodically with OOMKilled true confirms it.</li><li>Set a realistic --memory limit so a leak kills one container instead of starving the host.</li></ul><p>Network or disk saturation:</p><ul><li>Compare NET I/O and BLOCK I/O deltas between two --no-stream samples to compute a rate.</li><li>A database writing heavily is normal; a web container writing heavily may be logging too much to its writable layer.</li></ul><p>In Compose, set limits in the service definition:</p><pre>services:<br>  api:<br>    image: taskflow:1.0.0<br>    mem_limit: 256m<br>    cpus: 1.0</pre><h3>Docker Stats versus production monitoring</h3><p>docker stats is excellent for debugging on one host. It has limits:</p><ul><li>It shows only the current moment, with no history and no graphs.</li><li>It has no alerting.</li><li>It covers one Docker host at a time.</li><li>It reports no application metrics such as request latency or error rates.</li></ul><p>When you need trends, alerts and multiple hosts, collect metrics continuously. A common stack is cAdvisor (exposes per-container metrics), Prometheus (scrapes and stores them) and Grafana (dashboards and alert rules). Add application metrics through client libraries so you can correlate resource usage with request behavior.</p><h3>Real-world use cases</h3><ul><li>Finding which container is eating the CPU on a shared build server.</li><li>Sizing memory limits before deploying to a cluster.</li><li>Reproducing an OOM kill locally with the same limit.</li><li>Quick sanity checks after a deployment.</li></ul><h3>Common mistakes</h3><ul><li>Running containers with no memory limit and treating the host’s total as the container’s budget.</li><li>Reading CPU % as a percentage of the whole host.</li><li>Setting the limit equal to typical usage, leaving no headroom for peaks.</li><li>Using docker stats as the only monitoring for production.</li><li>Ignoring PIDS growth, which can reveal a process or thread leak.</li></ul><h3>Best practices</h3><ul><li>Set CPU and memory limits for every long-running service.</li><li>Record a baseline during normal load, then compare after changes.</li><li>Alert on sustained values and OOM kills, not momentary spikes.</li><li>Log to stdout instead of writing large files into the container filesystem.</li><li>Move to Prometheus and Grafana as soon as you run more than a couple of hosts.</li></ul><h3>Challenge</h3><p>Run the mem-hog example with a 256 MB limit, record how long it takes to be OOM killed, then change the loop so it frees memory every 100 iterations and confirm that usage stays flat.</p><h3>Related in this series</h3><ul><li>Previous: DevOps Concepts 11/25 — Docker Cache: Speeding Up Container Builds</li><li>Next: DevOps Concepts 13/25 — Docker Scout: Identifying Vulnerabilities in Container Images</li><li>Also see: DevOps Concepts 21/25 — Kubernetes Pod Lifecycle: Understanding How Pods Live and Terminate</li></ul><p>This is Article 12 of 25 in the DevOps Concepts Series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98628f94015c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevOps Concepts 11/25 — Docker Cache: Speeding Up Container Builds]]></title>
            <link>https://medium.com/@anubhavbhatt/devops-concepts-11-25-docker-cache-speeding-up-container-builds-9b2fc3635dc9?source=rss-9379711ef44------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b2fc3635dc9</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Anubhav Bhatt]]></dc:creator>
            <pubDate>Tue, 10 Nov 2026 07:46:01 GMT</pubDate>
            <atom:updated>2026-11-10T07:46:01.584Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G0INmM06wY38ZHR6TzFx6Q.png" /><figcaption>DevOps Concepts — Docker Cache: Speeding Up Container Builds</figcaption></figure><p>This is Article 11 of 25 in the DevOps Concepts Series (Part 3 of 6: Docker Deep Dive). A Docker build that reinstalls every dependency on each code change wastes minutes per commit. This article starts with a slow Dockerfile and fixes it step by step.</p><h3>Key Takeaways</h3><pre>- Docker caches each layer; a step is reused only if the instruction and its inputs are unchanged.<br> - Once one layer is invalidated, every layer after it rebuilds.<br> - Copy dependency manifests and install dependencies before copying application code.<br> - BuildKit cache mounts keep the package manager cache between builds without putting it in the image.<br> - CI runners start empty, so export and import the cache with --cache-to and --cache-from.<br> - A good .dockerignore prevents unrelated file changes from busting the cache.</pre><h3>How does Docker build caching work?</h3><p>When Docker executes a Dockerfile, it checks each instruction against previous builds. For a RUN instruction it compares the instruction text and the parent layer. For COPY and ADD it also compares a checksum of the files being copied. If everything matches, Docker reuses the stored layer and prints CACHED. If not, it runs the step and creates a new layer.</p><p>The key rule: cache invalidation cascades. When one step misses, all following steps must run again, because their parent layer changed. That is why instruction order decides how fast your builds are.</p><h3>Start with a slow Dockerfile</h3><pre>FROM python:3.12-slim<br>WORKDIR /srv<br>COPY . .<br>RUN pip install -r requirements.txt<br>CMD [&quot;uvicorn&quot;, &quot;app.main:app&quot;, &quot;--host&quot;, &quot;0.0.0.0&quot;, &quot;--port&quot;, &quot;8000&quot;]</pre><p>COPY . . copies the whole project, including source files you edit constantly. Change one line in app/main.py and the checksum of that layer changes. The pip install below it then runs again even though requirements.txt did not change.</p><p>Measure it:</p><pre>time docker build --no-cache -t taskflow:slow .<br># edit a comment in app/main.py<br>time docker build -t taskflow:slow .</pre><p>On the second build you will see pip install run again and download every package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8n-rd4HyYblclFn96Xej0w.png" /><figcaption>Comparison of a slow build rebuilding every layer and a cached build rebuilding only the app layer</figcaption></figure><h3>Fix 1: separate dependencies from code</h3><pre>FROM python:3.12-slim<br>WORKDIR /srv<br>COPY requirements.txt .<br>RUN pip install -r requirements.txt<br>COPY app ./app<br>CMD [&quot;uvicorn&quot;, &quot;app.main:app&quot;, &quot;--host&quot;, &quot;0.0.0.0&quot;, &quot;--port&quot;, &quot;8000&quot;]</pre><p>Now the install layer depends only on requirements.txt. Editing application code invalidates only the final COPY app layer, so the rebuild takes seconds. Repeat the experiment and the output shows CACHED for the base image, the requirements.txt copy and the install.</p><p>Add a .dockerignore so irrelevant changes do not alter the build context:</p><pre>.git<br>__pycache__<br>*.pyc<br>.venv<br>tests<br>*.md</pre><h3>Fix 2: BuildKit and cache mounts</h3><p>BuildKit is the modern build engine and the default in current Docker versions. It runs independent stages in parallel and supports mounts that exist only during a RUN step.</p><p>When requirements.txt does change, the install layer rebuilds and pip downloads everything again. A cache mount keeps pip&#39;s download cache across builds without storing it in the image:</p><pre># syntax=docker/dockerfile:1<br>FROM python:3.12-slim<br>WORKDIR /srv<br>COPY requirements.txt .<br>RUN --mount=type=cache,target=/root/.cache/pip \<br>    pip install -r requirements.txt<br>COPY app ./app<br>CMD [&quot;uvicorn&quot;, &quot;app.main:app&quot;, &quot;--host&quot;, &quot;0.0.0.0&quot;, &quot;--port&quot;, &quot;8000&quot;]</pre><p>Note the missing --no-cache-dir flag: here you want pip to use its cache. The cache mount lives on the build host, is shared across builds, and never ends up in a layer, so the image stays small.</p><p>You can also bind-mount files so they do not need their own layer:</p><pre>RUN --mount=type=bind,source=requirements.txt,target=requirements.txt \<br>    --mount=type=cache,target=/root/.cache/pip \<br>    pip install -r requirements.txt</pre><h3>Fix 3: multi-stage builds</h3><p>Multi-stage builds let you build in a heavy stage and copy only the result into a clean one. BuildKit only builds the stages that the final target needs, and stages that do not depend on each other build in parallel.</p><pre># syntax=docker/dockerfile:1<br>FROM python:3.12-slim AS deps<br>WORKDIR /build<br>RUN python -m venv /opt/venv<br>ENV PATH=&quot;/opt/venv/bin:$PATH&quot;<br>COPY requirements.txt .<br>RUN --mount=type=cache,target=/root/.cache/pip \<br>    pip install -r requirements.txt</pre><pre>FROM python:3.12-slim AS runtime<br>COPY --from=deps /opt/venv /opt/venv<br>ENV PATH=&quot;/opt/venv/bin:$PATH&quot;<br>WORKDIR /srv<br>COPY app ./app<br>CMD [&quot;uvicorn&quot;, &quot;app.main:app&quot;, &quot;--host&quot;, &quot;0.0.0.0&quot;, &quot;--port&quot;, &quot;8000&quot;]</pre><p>A code change touches only the last two instructions. The deps stage stays cached until the requirements change.</p><h3>Fix 4: external cache for CI</h3><p>Local cache survives only on the machine that built it. A fresh CI runner has an empty cache, so every pipeline run starts from zero. Export the cache somewhere persistent with buildx.</p><p>Registry cache:</p><pre>docker buildx build \<br>  --cache-from type=registry,ref=ghcr.io/&lt;user&gt;/taskflow:buildcache \<br>  --cache-to   type=registry,ref=ghcr.io/&lt;user&gt;/taskflow:buildcache,mode=max \<br>  -t ghcr.io/&lt;user&gt;/taskflow:${GITHUB_SHA} --push .</pre><p>GitHub Actions cache backend inside a workflow:</p><pre>- uses: docker/setup-buildx-action@v3<br>- uses: docker/build-push-action@v6<br>  with:<br>    context: .<br>    push: true<br>    tags: ghcr.io/${{ github.repository }}:${{ github.sha }}<br>    cache-from: type=gha<br>    cache-to: type=gha,mode=max</pre><p>mode=max exports cache for all intermediate stages, not just the final image, which matters for multi-stage builds. The pipeline-level view of this belongs to Article 15 on GitHub Actions optimization.</p><h3>Why do cache misses happen?</h3><p>When a build is slower than expected, look for:</p><ul><li>Copying the whole project before installing dependencies.</li><li>A COPY that includes files that change every build, such as logs, build output or a timestamp file.</li><li>Missing .dockerignore, so .git changes alter the context.</li><li>ARG values that change per build (for example a build timestamp or commit SHA) declared before expensive steps. An ARG change invalidates the steps after its use.</li><li>RUN apt-get update on its own line, which can be cached stale; combine it with apt-get install in one RUN.</li><li>Changing the base image tag, or a floating tag like latest that moved.</li><li>A fresh CI runner with no cache imported.</li><li>A different builder or builder driver than the one that stored the cache.</li></ul><p>To see what happened, use plain progress output:</p><pre>docker build --progress=plain -t taskflow:test .</pre><p>Steps marked CACHED were reused; anything else ran.</p><h3>Real-world use cases</h3><ul><li>Teams with large dependency sets (machine learning, scientific Python) where an install takes several minutes.</li><li>Monorepos where many services share a base image and build pipeline.</li><li>CI pipelines that build on every pull request and need quick feedback.</li><li>Developer laptops where a rebuild after each edit must stay under a few seconds.</li></ul><h3>Common mistakes</h3><ul><li>Putting COPY . . near the top.</li><li>Adding --no-cache to every build &quot;to be safe&quot; and giving up caching entirely.</li><li>Using --no-cache-dir together with a pip cache mount, which defeats the mount.</li><li>Baking build timestamps into early layers.</li><li>Expecting local cache to exist in CI.</li><li>Writing secrets into a cached layer; use --mount=type=secret for build-time secrets so they never land in a layer.</li></ul><h3>Best practices</h3><ul><li>Order instructions from least to most volatile.</li><li>Keep dependency installation in its own layer driven only by the manifest or lock file.</li><li>Maintain .dockerignore.</li><li>Use cache mounts for package managers.</li><li>Use --cache-from and --cache-to in CI with mode=max for multi-stage builds.</li><li>Rebuild without cache on a schedule (for example weekly) so base image patches are picked up.</li></ul><h3>Challenge</h3><p>Take the slow Dockerfile, time three scenarios (clean build, code-only change, requirements change), then repeat after each fix and write down the numbers. Which fix gave the biggest improvement for which scenario?</p><h3>Related in this series</h3><ul><li>Previous: DevOps Concepts 10/25 — Docker Images: Understanding Layers, Registries, and Image Management</li><li>Next: DevOps Concepts 12/25 — Docker Stats: Monitoring Container Resource Usage</li><li>Also see: DevOps Concepts 15/25 — GitHub Actions Optimization: Building Faster and More Efficient Pipelines</li></ul><p>This is Article 11 of 25 in the DevOps Concepts Series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b2fc3635dc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design Caching 2/3 — Distributed Caching: Cache Patterns, Consistency and Sharding]]></title>
            <link>https://medium.com/@anubhavbhatt/system-design-caching-2-3-distributed-caching-cache-patterns-consistency-and-sharding-c93b0e323e98?source=rss-9379711ef44------2</link>
            <guid isPermaLink="false">https://medium.com/p/c93b0e323e98</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[Anubhav Bhatt]]></dc:creator>
            <pubDate>Tue, 10 Nov 2026 04:41:01 GMT</pubDate>
            <atom:updated>2026-11-10T04:41:01.536Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RrhtvrGZev8pNbfv9mGXEQ.png" /><figcaption>System Design Caching — Distributed Caching: Cache Patterns, Consistency and Sharding</figcaption></figure><p>Adding a cache speeds up reads, but it creates a new problem: your application now holds at least two copies of the same data, the primary database and the cache. When the database changes, the cached copy has to catch up. Should you update the cache or delete the key? What if two requests update the same data? What if the cache update fails after the database commits?</p><p>This is Part 2 of the System Design Caching Series. Cache consistency is not about keeping every copy identical at every moment. It is about defining how and when copies become consistent again.</p><h3>Key Takeaways</h3><pre>- Cache-aside is simple but can suffer from stale-set race conditions.<br> - Deleting a cache entry after a database write is generally safer than updating it under concurrent writes.<br> - Leases block certain stale writes and reduce duplicate regeneration of hot keys.<br> - Write-through does not make the cache and database update atomically.<br> - A transactional outbox or CDC makes invalidation reliable.<br> - Write-behind raises write throughput at the cost of durability risk.<br> - TTL sets a practical freshness boundary; define it in measurable terms.<br> - Local caches are fast but create independent copies; consistent hashing limits key movement when nodes change.</pre><h3>How does the cache-aside pattern work?</h3><p>Cache-aside is one of the most widely used strategies.</p><ol><li>The application checks Redis for the key.</li><li>On a hit, it returns the cached value.</li><li>On a miss, it queries the database, stores the result in Redis and returns it.</li></ol><p>On a database write, update the database first, then delete the cache entry. The next read fetches the latest value and repopulates the cache.</p><h3>Why delete instead of update?</h3><p>Deletes are idempotent: repeating one causes no extra problems. Concurrent updates can arrive out of order, so writing a value into the cache directly can let an older value overwrite a newer one.</p><h3>The stale-set race condition</h3><ul><li>Request A reads an old value from the database after a cache miss.</li><li>Request B updates the database with a new value.</li><li>Request B deletes the cache key.</li><li>Request A finishes its earlier query and writes the old value into Redis.</li><li>Later requests receive stale data.</li></ul><p>The database has the new value while the cache keeps the old one.</p><h3>How leases solve it</h3><p>Facebook described a lease mechanism for this. On a cache miss, the cache can hand the client a token tied to that key, and the client must present the token to populate the cache. If an invalidation happens in the meantime, the token is revoked, so a late writer with stale data is rejected.</p><p>Leases also cut duplicate regeneration: only one client gets permission to rebuild a popular missing key during the lease period, so others do not rebuild the same value. Facebook reported roughly a 13x reduction in peak database query rate for heavily requested keys.</p><h3>How is cache-aside different from read-through?</h3><ul><li><strong>Cache-aside:</strong> the application manages reads and population, queries the database on a miss, and decides when to invalidate.</li><li><strong>Read-through:</strong> the application asks the cache for data, and the cache fetches missing data from the data source itself.</li></ul><p>These names describe different responsibilities, not a fixed contract. The actual mechanics matter more than the pattern name.</p><h3>What does write-through caching do?</h3><p>In a write-through design, a write updates both the cache and the underlying data store, so later reads find fresh data in the cache.</p><p>The catch is atomicity. The cache and the database are independent systems: a cache write can succeed while the database write fails, or the reverse, and two clients can run operations in different orders. Nothing like a distributed transaction guarantees both updates succeed together.</p><p>Retrying does not fully fix this. An in-memory retry disappears if the process crashes, and a durable retry can itself fail. Write-through moves the consistency problem; it does not remove it.</p><h3>How do you make cache invalidation reliable?</h3><p>Two approaches make sure an invalidation is not lost.</p><h3>Transactional outbox</h3><ul><li>The application updates business data inside a database transaction.</li><li>In the same transaction, it records an event describing the cache invalidation.</li><li>A background worker reads the outbox and deletes the relevant Redis key.</li><li>If the application crashes after commit, the invalidation intent is still stored.</li></ul><p>Advantages: invalidation events are durable, business data and invalidation intent commit together, and failed events can be retried. Limitations: application code must remember to write the event, and other systems that write straight to the database can bypass it.</p><h3>Change data capture (CDC)</h3><p>CDC reads changes from the database’s committed transaction log, identifies changes to relevant records and publishes invalidation events. A cache consumer processes them and removes outdated entries. Facebook described extracting invalidations from committed database statements, and Uber described consuming MySQL binlogs to invalidate Redis entries.</p><p>Advantages: invalidation follows committed changes, it can capture writes made outside a particular code path, and events can be replayed.</p><h3>Tombstones and timestamped invalidation</h3><p>A tombstone is an invalidation marker that records a key was invalidated at a given time. Older cache writes arriving after it can be rejected, which stops delayed operations from restoring stale values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*nUILixSKbRQLrKQE" /></figure><h3>What is write-behind caching?</h3><p>Write-behind (write-back) changes the order. The application writes to the cache, the cache acknowledges, and a background queue updates the database later.</p><p>Benefits: fewer synchronous database writes, merged updates to the same key, and better write throughput for suitable workloads.</p><p>Risks: the cache temporarily becomes the effective source of truth, a cache failure can lose acknowledged writes, durability depends on replication and queue guarantees, and the system must handle delayed writes and recovery.</p><p>It fits view counters, analytics aggregation, non-critical metrics and workloads where updates can be consolidated. It is hard to justify for financial balances or any data where losing an acknowledged write is unacceptable.</p><h3>How does TTL bound consistency?</h3><p>TTL is one of the simplest ways to limit how long cached data can stay outdated. Instead of perfect synchronization, the application accepts a freshness window.</p><ul><li>A shorter TTL reduces the maximum lifetime of stale data.</li><li>A longer TTL improves reuse but widens the freshness gap.</li><li>A TTL near zero means nearly every request misses.</li><li>Write-heavy workloads usually need shorter TTLs than read-heavy ones.</li></ul><p>A soft TTL can be stored inside the cached value. When it expires, keep serving the previous value and refresh it in the background, so users do not wait on the database. It is an application-level version of stale-while-revalidate.</p><p>Define consistency in measurable terms, such as “data must update within five minutes”, instead of just calling a cache consistent.</p><h3>What is multi-level caching?</h3><p>Large applications often use two levels.</p><ul><li><strong>L1, local or near cache:</strong> inside the application process. Very fast and avoids network calls to Redis, but each instance keeps its own copy.</li><li><strong>L2, distributed cache:</strong> shared across instances, commonly Redis.</li></ul><p>A lookup works like this:</p><ol><li>Check the local cache; return on a hit.</li><li>On a miss, check Redis; if found, populate the local cache.</li><li>If both miss, read from the database and populate both levels.</li></ol><p>The cost is consistency. Ten application processes can hold ten versions of the same record, invalidation messages can be delayed or lost, and a local cache can keep serving old data after Redis has been updated. Near caching improves latency and availability but adds consistency complexity.</p><h3>How do you shard a cache?</h3><p>When one cache server cannot handle the memory or throughput, data has to be spread across nodes.</p><h3>Modulo-based sharding</h3><pre>node = hash(key) mod N</pre><p>N is the number of cache nodes. The problem appears when you grow from three nodes to four: the modulo changes, many keys map to different nodes, the new assignments do not hold those values, and the result is a wave of misses. The database sees a sudden traffic spike. This is cache reshuffling.</p><h3>Consistent hashing</h3><p>Consistent hashing limits how many keys move when the cluster changes. Nodes sit on a logical hash ring, each at several positions through virtual nodes. Each key is hashed onto the ring and assigned to the next node clockwise. Adding a node moves only a portion of the keys.</p><h3>Redis Cluster and Memcached</h3><p>Redis Cluster distributes keys with hash slots. During resharding, slots and their keys move between instances, and Redis can redirect requests while a slot migrates. Memcached usually relies on client-side hashing and routing and has no equivalent server-to-server coordination for moving entries.</p><p>Sharding is not just adding servers. It is also how keys move and what happens to requests during redistribution.</p><h3>Conclusion</h3><p>Every caching pattern is a decision about where the disagreement between copies is allowed to live. Delete on write, use leases or tombstones to stop late stale writes, make invalidation durable with an outbox or CDC, and state your freshness window as a number. Part 3 covers what happens when these systems meet production traffic.</p><p>Series: System Design Caching Series, Part 2 of 3.</p><p><strong>Previous: Part 1: Caching Fundamentals: Redis, Memory Management and CDN Architecture.</strong></p><p><strong>Next: Part 3: Production Caching: Failure Scenarios, Performance and Scaling.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c93b0e323e98" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>