<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Emily Woods</title>
    <description>The latest articles on DEV Community by Emily Woods (@emilywoodsnyc).</description>
    <link>https://dev.to/emilywoodsnyc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3912599%2Fc95a7ee1-41d2-4e1e-994d-e1aedab86d39.png</url>
      <title>DEV Community: Emily Woods</title>
      <link>https://dev.to/emilywoodsnyc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emilywoodsnyc"/>
    <language>en</language>
    <item>
      <title>If I Were Preparing for Software Engineering Roles in 2027, Here’s Where I’d Start</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Thu, 03 Dec 2026 16:36:17 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/if-i-were-preparing-for-software-engineering-roles-in-2027-heres-where-id-start-p0f</link>
      <guid>https://dev.to/emilywoodsnyc/if-i-were-preparing-for-software-engineering-roles-in-2027-heres-where-id-start-p0f</guid>
      <description>&lt;h3&gt;
  
  
  4-week plan for turning scattered studying into work you can explain, improve and show.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjlr2t90fvb5x1jt9uyx4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjlr2t90fvb5x1jt9uyx4.png" alt="A mechanical snail carries a map toward one software role in 2027" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine reaching the end of January with a longer list of saved resources and the same fear of opening a job application.&lt;/p&gt;

&lt;p&gt;You studied after work. You watched the explanations. You even built a schedule with different colors for different subjects, because apparently anxiety also enjoys a nice spreadsheet.&lt;/p&gt;

&lt;p&gt;But when someone asks what you feel more confident doing, the answer is still a little blurry.&lt;/p&gt;

&lt;p&gt;That is the preparation trap I want to avoid going into 2027.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My starting point would be one role I want and one honest attempt at doing the work it requires.&lt;/strong&gt; Everything else has to earn a place in the week.&lt;/p&gt;

&lt;p&gt;Here is how I’d turn that into a plan, especially if you already know one programming language but your preparation feels scattered.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your first decision happens before you study
&lt;/h2&gt;

&lt;p&gt;Pick a narrower target for the next month. You can change it later, but you need something specific enough to guide your choices now.&lt;/p&gt;

&lt;h3&gt;
  
  
  Make a one page target
&lt;/h3&gt;

&lt;p&gt;Find five live job descriptions that fit your experience and location. Check eligibility, including any work authorization requirements, before treating a role as a realistic target.&lt;/p&gt;

&lt;p&gt;Write down what overlaps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Role and level&lt;/strong&gt; might be early-career backend engineering, rather than anything involving code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recurring work&lt;/strong&gt; could include APIs, database queries, testing and debugging existing services.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interview format&lt;/strong&gt; belongs here too, using official guidance or recruiter confirmation where available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One gap to investigate&lt;/strong&gt; should be something you cannot yet demonstrate, not every technology you have never touched.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a hypothetical backend candidate, the first page might point toward Python, SQL and API behavior. That candidate does not need to add mobile development because a compelling video appeared on Wednesday.&lt;/p&gt;

&lt;p&gt;Five postings are a planning sample, not a census of the market. Their job is to help you decide what to practice next.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw7i3rgpdoch4ts5pj06r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw7i3rgpdoch4ts5pj06r.png" alt="Five relevant job postings become one role target and a next task" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Stop waiting to feel ready for a baseline
&lt;/h2&gt;

&lt;p&gt;Before buying anything or rebuilding your study plan, give yourself three small attempts across two evenings.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Solve one coding problem&lt;/strong&gt; without a generated solution. Explain your approach, test it and name its cost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Change one existing function&lt;/strong&gt; in a small project. Reproduce its current behavior before editing it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain one past decision&lt;/strong&gt; aloud, including the constraint, your contribution and what happened afterward.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use course or personal work if you do not have professional experience. Keep the context honest.&lt;/p&gt;

&lt;p&gt;After each attempt, record where progress stopped. Was the difficulty understanding the problem, choosing an approach, implementing it, checking it or explaining it?&lt;/p&gt;

&lt;p&gt;Those are different problems, which means they need different practice.&lt;/p&gt;

&lt;p&gt;If finding a starting prompt is slowing you down, choose one from these &lt;a href="https://prachub.com/questions?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;company and role filtered practice questions&lt;/a&gt;. Save your first attempt and the point where you needed help. You are choosing a baseline, so resist collecting another thirty questions before trying one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The first win is being able to name the gap accurately.&lt;/strong&gt; You can build a useful week around that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let one weak point shape your first week
&lt;/h2&gt;

&lt;p&gt;Suppose our backend candidate can follow a hash map solution but cannot produce it without looking at the explanation.&lt;/p&gt;

&lt;p&gt;More explanations may feel comfortable. The missing practice is producing the reasoning independently.&lt;/p&gt;

&lt;p&gt;Try this loop with a problem that is difficult enough to expose a gap but small enough to revisit.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Attempt it first&lt;/strong&gt;, and write a simple approach even if it is inefficient.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Study the missing idea&lt;/strong&gt;, then connect it to the exact place your attempt broke down.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Close the explanation&lt;/strong&gt; and implement it again from your own notes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return later&lt;/strong&gt; and solve a related variation without copying the earlier code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Change something meaningful in the variation. Allow duplicates, alter the output requirement or make the input too large for the original approach.&lt;/p&gt;

&lt;p&gt;If the solution falls apart, write down why. That note is more useful than a green checkmark you cannot reproduce.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1klvsfvzszuksoi32vdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1klvsfvzszuksoi32vdl.png" alt="Practice loop from independent attempt through study, rebuilding and a variation" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Meanwhile, keep one short practice session for a strength you already have. Fixing the weakest part should not mean forgetting everything else.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare for the interview you actually booked
&lt;/h2&gt;

&lt;p&gt;I’m not planning around the idea that every company will interview the same way in 2027. Current guidance already gives us reasons to expect variation.&lt;/p&gt;

&lt;p&gt;Amazon’s &lt;a href="https://www.amazon.jobs/content/en/how-we-hire/university/sde-oa" rel="noopener noreferrer"&gt;student and graduate SDE assessment guidance&lt;/a&gt; still includes coding and technical problem solving. DoorDash describes a &lt;a href="https://careersatdoordash.com/blog/doordash-is-rebuilding-its-engineering-interviews-around-ai/" rel="noopener noreferrer"&gt;60-minute AI-assisted engineering session&lt;/a&gt; involving an existing project, verification and communication.&lt;/p&gt;

&lt;p&gt;Neither page tells us what every employer will do next year. Your invitation and recruiter should settle the rules for your particular round.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keep two modes in your practice
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Without AI&lt;/strong&gt;, practice explaining a problem, writing the core solution and checking its behavior yourself. This shows you which parts you actually understand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With AI&lt;/strong&gt;, practice giving a bounded task, inspecting the changes, running a meaningful check and explaining what you accepted or rejected. Use your own practice project, and follow the actual interview’s tool rules when the time comes.&lt;/p&gt;

&lt;p&gt;For example, ask an assistant to add pagination to a small endpoint. Before accepting the result, check page boundaries, invalid inputs and whether the ordering is stable enough for the chosen approach.&lt;/p&gt;

&lt;p&gt;The useful evidence is the change you can defend, including the mistake you caught. A generated explanation that sounds confident is not that evidence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make one project carry more of the learning
&lt;/h2&gt;

&lt;p&gt;During the second week, choose a small project you can change repeatedly. Something you already have is often enough.&lt;/p&gt;

&lt;p&gt;For our backend candidate, an appointment-booking service gives us several connected exercises without requiring a grand startup idea.&lt;/p&gt;

&lt;h3&gt;
  
  
  Start with behavior someone can test
&lt;/h3&gt;

&lt;p&gt;Create a booking, retrieve it and cancel it. Write down the expected response when a booking does not exist.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add one constraint that matters
&lt;/h3&gt;

&lt;p&gt;Prevent two bookings for the same slot. Explain where that rule is enforced and write a check that would expose a duplicate.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduce a failure and investigate it
&lt;/h3&gt;

&lt;p&gt;Simulate a database timeout or a duplicate request. Record what the caller sees and what the logs reveal, then make one defensible improvement.&lt;/p&gt;

&lt;p&gt;Now you have material for discussing data modeling, debugging and design trade-offs. The feature list can stay small while the explanation gets much stronger.&lt;/p&gt;

&lt;p&gt;Frontend candidates can use a search interface and work through stale responses, keyboard access and loading states. Adjust the project to the work your target roles actually describe.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F69xoar3cr5fhwdh83a5d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F69xoar3cr5fhwdh83a5d.png" alt="A booking project develops through behavior, constraints and failures" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Put the work into a week you can repeat
&lt;/h2&gt;

&lt;p&gt;Here is a starting schedule for someone with roughly six hours a week. If you have less time, stretch the plan. Four weeks is a review point, not a promise of an offer.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Monday (60 minutes):&lt;/strong&gt; Attempt a targeted coding problem and record the gap.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tuesday (60 minutes):&lt;/strong&gt; Make one project change and test its behavior.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thursday (60 minutes):&lt;/strong&gt; Revisit the weak point with a variation or a fresh debugging task.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Saturday (90 minutes):&lt;/strong&gt; Run a mock session, review it and practice one truthful experience story.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sunday (90 minutes):&lt;/strong&gt; Improve one application, check suitable openings and decide what next week needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1/ Use the first week to choose the target and establish your baseline.&lt;/p&gt;

&lt;p&gt;2/ During week two, produce a project change you can explain.&lt;/p&gt;

&lt;p&gt;3/ In week three, test yourself under the likely interview format.&lt;/p&gt;

&lt;p&gt;4/ Use week four to compare your work with the baseline and adjust.&lt;/p&gt;

&lt;p&gt;If design is central to your target level, give it a dedicated block by replacing part of the coding practice. Work through requirements, data flow, failures and a trade-off. Do not quietly turn six hours into sixteen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Every week should leave something you can inspect.&lt;/strong&gt; A solution, a tested change, a mock recording or an application is much easier to assess than the feeling that you studied a lot.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start applying while you are still improving
&lt;/h2&gt;

&lt;p&gt;Preparation can become a very convincing reason to postpone the part where someone might say no.&lt;/p&gt;

&lt;p&gt;Once your basic materials accurately represent your work, apply to suitable roles while the practice continues. Keep your strongest relevant evidence easy to find, whether it comes from a job, a course or a personal project.&lt;/p&gt;

&lt;p&gt;Track the stage where progress stops, without treating every rejection as a diagnosis.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Few replies&lt;/strong&gt; are a reason to review targeting, eligibility and how clearly your resume shows relevant work. Market conditions and timing matter too.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Difficulty in coding screens&lt;/strong&gt; points toward examining your actual attempts and recurring mistakes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Difficulty explaining projects&lt;/strong&gt; calls for practicing decisions, ownership and trade-offs aloud.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unclear feedback&lt;/strong&gt; is a reason to seek a mock interview or specific review, rather than invent an explanation for the rejection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One outcome is noisy. Look for patterns across several comparable attempts before rebuilding the whole plan.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm1r5y0v4b2vx2lntoj9m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm1r5y0v4b2vx2lntoj9m.png" alt="Practice and application evidence guide next week without diagnosing one rejection" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Give January a smaller job
&lt;/h2&gt;

&lt;p&gt;Return to the person at the beginning of this article, staring at a beautiful study spreadsheet.&lt;/p&gt;

&lt;p&gt;By the end of the month, I want them to have something more reassuring than a longer resource list.&lt;/p&gt;

&lt;p&gt;They can name the roles they are targeting. They can revisit a problem that used to stop them. They can show a project change, explain why it works and point to applications they actually sent.&lt;/p&gt;

&lt;p&gt;They may still feel nervous. Progress does not require pretending otherwise.&lt;/p&gt;

&lt;p&gt;Tonight, find the five postings and choose a time for your first baseline attempt. Leave the rest of the roadmap alone until you have seen what that attempt teaches you.&lt;/p&gt;

&lt;p&gt;You do not need to become a different person before you start. You need a next step that is small enough to take and honest enough to learn from.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/p&gt;

</description>
      <category>career</category>
    </item>
    <item>
      <title>AI Engineer Interview: Why Did You Build an Agent for That?</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Thu, 03 Dec 2026 16:35:35 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/ai-engineer-interview-why-did-you-build-an-agent-for-that-c1i</link>
      <guid>https://dev.to/emilywoodsnyc/ai-engineer-interview-why-did-you-build-an-agent-for-that-c1i</guid>
      <description>&lt;h3&gt;
  
  
  One support ticket, two possible architectures, and a much stronger way to explain your AI project.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnoq1haxjao5a4wic5fi2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnoq1haxjao5a4wic5fi2.png" alt="A surreal bird automaton with a house-shaped body questions an AI agent architecture" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine explaining your AI project in an interview. You have a planner, a researcher, a reviewer, and a very pretty diagram connecting all three.&lt;/p&gt;

&lt;p&gt;Then someone asks whether a function could do the same job.&lt;/p&gt;

&lt;p&gt;Suddenly, the difficult part is explaining why those boxes deserve to exist.&lt;/p&gt;

&lt;p&gt;Honestly, I think this is a better question to practice than memorizing another agent framework. It asks you to separate what the model can do from what your product actually needs.&lt;/p&gt;

&lt;p&gt;You can build something impressive without giving it permission to improvise at every step. Let’s work through one small example so you have an answer you can defend.&lt;/p&gt;

&lt;h2&gt;
  
  
  First, name the decision you are handing over
&lt;/h2&gt;

&lt;p&gt;For this exercise, use a practical distinction.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ordinary code&lt;/strong&gt; applies known rules to inputs, like checking whether an order belongs to an account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An LLM workflow&lt;/strong&gt; uses a model inside a route your code controls, like extracting a request type before choosing a predefined branch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An agent&lt;/strong&gt; lets the model choose its next action based on what it has learned, like deciding which source to investigate after a lookup fails.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Adding a model call does not automatically make every surrounding step autonomous. A workflow can branch, retry and use several models while keeping its route under program control.&lt;/p&gt;

&lt;p&gt;Anthropic makes this control-flow distinction in its &lt;a href="https://www.anthropic.com/research/building-effective-agents" rel="noopener noreferrer"&gt;engineering guide to agents and workflows&lt;/a&gt;. The useful question is who chooses the next step, rather than how many boxes your diagram contains.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpqnt5f04cykku1jyhh14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpqnt5f04cykku1jyhh14.png" alt="Code, workflows and agents differ in who chooses the next step" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the project a job small enough to finish
&lt;/h2&gt;

&lt;p&gt;Here is our fictional product requirement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Help a support teammate draft replies to order-status tickets. Every reply stays a draft until a human reviews it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are not building a general customer-service employee. We are helping someone answer a specific kind of message with less searching and fewer unsupported claims.&lt;/p&gt;

&lt;p&gt;That gives us a first version with five steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Read the ticket&lt;/strong&gt; and extract its intent and any order ID.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate the output&lt;/strong&gt; and check that the authenticated account can access that order.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fetch the status&lt;/strong&gt; through a read-only order service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Draft a reply&lt;/strong&gt; using the returned facts, with missing information left explicit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Send it to human review&lt;/strong&gt;, without granting the model a send or refund tool.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the ID is missing, ask for it. If access fails, do not reveal the order. If the service times out, report the lookup failure rather than inventing a delivery date.&lt;/p&gt;

&lt;p&gt;Nothing here requires the model to invent a plan. Language understanding is useful, but the route is already known.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My starting choice is a workflow because the requirement gives me a workflow.&lt;/strong&gt; That is a reason you can explain without apologizing for the diagram being small.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkqvbue5prpsyshnw6n8s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkqvbue5prpsyshnw6n8s.png" alt="Order-support workflow validates access before retrieving facts and drafting a reply" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try applying that distinction to this &lt;a href="https://prachub.com/interview-questions/how-you-use-ai-tools-day-to-day-and-build-agents-to-automate-your-work?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;Yahoo tagged question about using AI and building agents at work&lt;/a&gt;. Pick one task you actually do and write down the decision you would delegate, the tool access it needs, and the evidence you would check afterward.&lt;/p&gt;

&lt;p&gt;Keep your answer before reading the guidance. It gives you something concrete to improve instead of another page you vaguely agree with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now change one requirement
&lt;/h2&gt;

&lt;p&gt;Suppose support also needs help investigating messy cases where an order appears delivered, a replacement was created, and the customer still says nothing arrived.&lt;/p&gt;

&lt;p&gt;Maybe the investigator needs the original shipment, then a replacement record, then a policy document. Which lookup is useful next depends on the previous result.&lt;/p&gt;

&lt;p&gt;This is where an agent becomes a candidate worth testing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed?
&lt;/h2&gt;

&lt;p&gt;We moved from retrieving one known record to choosing among possible investigation steps. The model could inspect a result and select the next authorized, read-only tool.&lt;/p&gt;

&lt;p&gt;That still does not settle the architecture. If the cases fall into a handful of predictable branches, expanding the workflow may be enough. An unfamiliar-looking ticket is not proof that we need an agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  What stays outside its control?
&lt;/h2&gt;

&lt;p&gt;For our practice version, the agent can gather evidence and prepare a draft. It cannot send messages, change account details or issue refunds.&lt;/p&gt;

&lt;p&gt;Enforce those limits in the tools and service permissions. A sentence in a prompt is not an authorization check.&lt;/p&gt;

&lt;p&gt;Also, treat text inside tickets and retrieved documents as data. A customer typing instructions to ignore the policy does not gain the ability to change our system’s permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give it a useful way to stop
&lt;/h2&gt;

&lt;p&gt;An investigation can get stuck while still looking busy. Another search feels productive, right up until someone has to read six nearly identical results.&lt;/p&gt;

&lt;p&gt;For a small exercise, allow at most three tool calls and a fixed time limit enforced by the application. Three is a practice constraint, not a universal production setting.&lt;/p&gt;

&lt;p&gt;Stop when any of these happens.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Enough evidence exists&lt;/strong&gt; to draft an answer with its supporting records.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A required fact is unavailable&lt;/strong&gt;, so a human or the customer needs to supply it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The call or time limit is reached&lt;/strong&gt;, so the system returns what it found and what remains unresolved.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A useful handoff might contain the original shipment status, the replacement record, and a note that the replacement carrier lookup failed. That is better than a confident promise that the package will arrive tomorrow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqyo0tzssqvi108u3v266.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqyo0tzssqvi108u3v266.png" alt="A bounded investigation has limited tools, stopping rules and a clear handoff" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the extra complexity compete against something
&lt;/h2&gt;

&lt;p&gt;Before declaring the agent better, keep the fixed workflow as your baseline.&lt;/p&gt;

&lt;p&gt;Build a small, clearly labeled practice set. Include straightforward requests as well as cases that should ask for help.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A valid order ID with an available delivery status.&lt;/li&gt;
&lt;li&gt;A message with no order ID.&lt;/li&gt;
&lt;li&gt;An order belonging to a different account.&lt;/li&gt;
&lt;li&gt;A timeout from the order service.&lt;/li&gt;
&lt;li&gt;Conflicting original and replacement shipment records.&lt;/li&gt;
&lt;li&gt;A ticket trying to instruct the system to bypass its rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For each case, write the acceptable outcome before running either version. An answer that should request more information must not receive credit merely because it sounds helpful.&lt;/p&gt;

&lt;p&gt;Run both designs on the same cases and inspect four things.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Correctness&lt;/strong&gt; means the answer matches the available facts or asks for the missing ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unsupported claims&lt;/strong&gt; include invented dates, promises and policy exceptions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time and cost&lt;/strong&gt; include failed calls and retries, not only the successful model response.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Human cleanup&lt;/strong&gt; includes corrections, verification and cases handed back unfinished.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Repeat runs where outputs vary. Six cases are a starting exercise, not proof of production reliability, and a later evaluation needs representative data and cases you did not tune against.&lt;/p&gt;

&lt;p&gt;Maybe the agent handles ambiguous cases better but takes longer on routine ones. Then route only the ambiguous cases to it. You do not have to give every ticket the most elaborate treatment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk1aclnioffsrgfpy9fqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk1aclnioffsrgfpy9fqx.png" alt="Compare a fixed workflow and a bounded agent on the same cases" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Skills fit without another robot on the diagram
&lt;/h2&gt;

&lt;p&gt;You might also package the support procedure, examples and relevant scripts as a Skill. Anthropic describes &lt;a href="https://claude.com/resources/articles/building-agents-with-skills-equipping-agents-for-specialized-work" rel="noopener noreferrer"&gt;Skills as reusable expertise that an agent can access&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That helps organize how to do the work. It does not, by itself, answer how much autonomy the application should allow.&lt;/p&gt;

&lt;p&gt;For our example, a Skill could explain how to interpret shipment records. The application still has to enforce account access, tool permissions and stopping limits.&lt;/p&gt;

&lt;p&gt;Please do not rebuild the entire architecture just because the vocabulary changed this week. Work out which missing capability the new piece actually supplies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finish your answer with the reason, not the framework
&lt;/h2&gt;

&lt;p&gt;For the fictional support system, a concise explanation could sound like this.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I’m starting with a fixed workflow because order-status replies have a known path. The model interprets the message and drafts the response, while code controls authorization, retrieval and the review step.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For ambiguous cases, I’ll compare that baseline with a bounded agent that can choose its next read-only lookup. I’ll keep the added autonomy only if it improves useful answers enough to justify the extra time, cost and review work.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Notice how much you can explain before naming a library.&lt;/p&gt;

&lt;p&gt;For your own project, take one sheet of paper and finish these three lines with details you can support.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The fixed route stops being sufficient when ______.&lt;/li&gt;
&lt;li&gt;The model may choose ______, but it may never ______.&lt;/li&gt;
&lt;li&gt;I will keep this design only if the comparison shows ______.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you cannot fill in the first line yet, that is a useful discovery. You may already have everything you need to build the smaller version.&lt;/p&gt;

&lt;p&gt;And honestly, being able to explain why you left something out makes your project much more interesting to discuss.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
    </item>
    <item>
      <title>Tell Me About a Time You Failed. Here’s How to Answer Without Making It Worse.</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Tue, 01 Dec 2026 22:35:21 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/tell-me-about-a-time-you-failed-heres-how-to-answer-without-making-it-worse-2n1o</link>
      <guid>https://dev.to/emilywoodsnyc/tell-me-about-a-time-you-failed-heres-how-to-answer-without-making-it-worse-2n1o</guid>
      <description>&lt;h3&gt;
  
  
  A practical way to tell the truth, own your part, and explain what changed without turning your answer into a confession.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F031i4ovs7v1h7pnw2lyb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F031i4ovs7v1h7pnw2lyb.png" alt="An engineer prepares an honest failure answer with notes about her decision, impact, and change." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can explain a complicated system and still feel your stomach drop when someone asks about a mistake.&lt;/p&gt;

&lt;p&gt;Suddenly, you’re doing two jobs. You’re trying to answer honestly, and you’re trying to stop the interviewer from deciding that this one moment is your entire personality.&lt;/p&gt;

&lt;p&gt;So the story gets polished. The missed deadline becomes an ambitious challenge. Your mistake disappears into a team misunderstanding. Somehow, the failure ends with everyone being impressed.&lt;/p&gt;

&lt;p&gt;Honestly, I find the smaller, less flattering answer more convincing when it explains what actually changed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You don’t need to sound flawless. You need to make your judgment visible.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with the part you’re tempted to hide
&lt;/h2&gt;

&lt;p&gt;Before writing an answer, finish these three lines in your own notes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;I was responsible for&lt;/strong&gt; a specific decision, task, or commitment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I got this part wrong&lt;/strong&gt; even if other things also went wrong.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Someone else felt the effect&lt;/strong&gt; in a way I can describe accurately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the second line is empty, you may have chosen a story about difficult circumstances rather than your own failure.&lt;/p&gt;

&lt;p&gt;If the third line is empty, keep looking for what the mistake cost. It might be a delayed handoff, extra work for a teammate, or a decision made with incomplete information. It doesn’t need to be a dramatic outage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3dbiy679srmh1nqbiq23.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3dbiy679srmh1nqbiq23.png" alt="Separate an external obstacle from your own decision and delayed response." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, missing a deadline because a dependency arrived late is the setting. Promising the date before checking that dependency, then waiting too long to raise the risk, is the part you can examine.&lt;/p&gt;

&lt;p&gt;That distinction gives you something useful to talk about without accepting blame for things you didn’t control.&lt;/p&gt;

&lt;p&gt;Try the &lt;a href="https://prachub.com/interview-questions/explain-how-you-handled-a-missed-commitment?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;Amazon-tagged missed-commitment question&lt;/a&gt; with a real example from your work or studies. Write those three lines before opening any guidance, then check whether you explained your own decision.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the story five places to land
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.aboutamazon.com/news/workplace/amazon-job-interview-tips" rel="noopener noreferrer"&gt;Amazon’s interview guidance&lt;/a&gt; recommends STAR and clear ownership of your actions. I like using five small notes to prepare a failure answer within that structure.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Commitment.&lt;/strong&gt; Explain what you agreed to deliver and who depended on it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decision.&lt;/strong&gt; Identify the assumption or action that was yours.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consequence.&lt;/strong&gt; Say what happened, including what recovery could not undo.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Repair.&lt;/strong&gt; Describe the steps you took and give teammates credit for theirs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Change.&lt;/strong&gt; Show what you do differently now and what evidence you actually have.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Keep the background short enough that the listener reaches your decision quickly. A minute spent explaining every team’s responsibilities can hide the very thing the question asks about.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxmxiedmrx1kwuxy1uv7c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxmxiedmrx1kwuxy1uv7c.png" alt="Five preparation notes cover commitment, decision, consequence, repair, and change." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are preparation notes, not a script to recite. The interviewer should be able to interrupt you without making the whole answer collapse.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s fix an answer that sounds almost useful
&lt;/h2&gt;

&lt;p&gt;Imagine an engineer who committed to delivering a data export before a customer’s Monday review. This is a fictional example to show the structure, not a story from my career.&lt;/p&gt;

&lt;h2&gt;
  
  
  The version that leaves too much out
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;We had a tight deadline, and another team delivered the schema late. I worked over the weekend, got the export out, and learned to communicate better.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We can see effort. Also, we still can’t see what the engineer owned, what the customer lost, or what changed afterward.&lt;/p&gt;

&lt;h2&gt;
  
  
  The version with something to examine
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Commitment and decision&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;I owned an export promised for Monday’s customer review. I estimated the work from a sample file without confirming that the final schema was stable.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Consequence&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;By Thursday, I knew the schema changes threatened the date. I waited until Friday to raise it because I thought I could recover. The customer had to hold the review without the export.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Repair&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;I told the account manager which assumption I’d missed and proposed a smaller export. Another engineer helped validate it, and we delivered it on Tuesday. That helped the customer continue, but it didn’t recover Monday’s meeting.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Change and evidence&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;For the next two exports, I confirmed the schema owner and sample before committing to a date. I also flagged unresolved dependencies at our planning checkpoint. Both met their revised commitments, although two deliveries aren’t proof that the problem can never happen again.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Notice that the second answer doesn’t magically turn the mistake into a triumph. It gives the listener decisions, consequences, actions, and limits they can ask about.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdm31j8s1qpd11v5wjhur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdm31j8s1qpd11v5wjhur.png" alt="Thursday risk, Friday escalation, Monday missed review, and Tuesday recovery show why a repair does not erase a miss." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can make this shorter when speaking. Keep the decision and consequence; trim the background first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare for the question after your answer
&lt;/h2&gt;

&lt;p&gt;A tidy opening is useful, but the follow-up is where a rehearsed story can get wobbly. Ask a friend to choose one of these without warning.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;When did you first know the plan was at risk?&lt;/strong&gt; Name the signal you had then, not the explanation you found afterward.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Why didn’t you escalate sooner?&lt;/strong&gt; Explain your reasoning at the time and where it failed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What did you personally change?&lt;/strong&gt; Separate your action from the team’s recovery.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How do you know the change helped?&lt;/strong&gt; Give an observed result, or say what you haven’t measured yet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If there hasn’t been another comparable project, say so. A new checklist is a change you’ve made; it isn’t evidence that future projects will succeed.&lt;/p&gt;

&lt;p&gt;I prefer that honest boundary to an impressive percentage someone invented while practicing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose a real mistake you can discuss responsibly
&lt;/h2&gt;

&lt;p&gt;You don’t need the worst day of your working life. Choose an example that answers the question, matters to the role, and lets you explain your contribution clearly.&lt;/p&gt;

&lt;p&gt;It can be missed dependency, an incorrect assumption, or feedback you acted on late can all give you enough substance.&lt;/p&gt;

&lt;p&gt;Keep confidential details out.&lt;/p&gt;

&lt;p&gt;Describe the system and impact without naming a customer or revealing private data, and use only numbers you can support.&lt;/p&gt;

&lt;p&gt;If you’re early in your career,&lt;br&gt;&lt;br&gt;
a relevant class project, internship, volunteer commitment, or group assignment can work.&lt;/p&gt;

&lt;p&gt;Keep its scale honest instead of dressing it up as a production incident.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practice the answer without memorizing the paragraph
&lt;/h2&gt;

&lt;p&gt;Give yourself one short rehearsal, using this order.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Write the five notes from memory, with one or two lines under each.&lt;/li&gt;
&lt;li&gt;Record a roughly two-minute answer as a starting point, not a universal interview time limit.&lt;/li&gt;
&lt;li&gt;Listen for where you hide behind &lt;em&gt;we&lt;/em&gt;, repeat the background, or skip the consequence.&lt;/li&gt;
&lt;li&gt;Answer one unexpected follow-up without restarting your story.&lt;/li&gt;
&lt;li&gt;Replace a vague lesson with one concrete behavior you changed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjz07z2x0dsfjxbf1n2cb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjz07z2x0dsfjxbf1n2cb.png" alt="A reusable five-part worksheet for preparing your own truthful failure story." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you use AI to review the transcript, ask it to identify missing facts and unclear ownership. Don’t let it supply your results, motives, or a happier ending.&lt;/p&gt;

&lt;p&gt;A useful answer can admit that a decision was wrong and still show that you are someone worth working with.&lt;/p&gt;

&lt;p&gt;That is the version worth practicing. You can leave the perfect redemption story in the drafts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>career</category>
      <category>interview</category>
    </item>
    <item>
      <title>Amazon Interview Question: Count the Votes. Now Let Everyone Change Their Mind.</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Tue, 01 Dec 2026 22:34:57 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/amazon-interview-question-count-the-votes-now-let-everyone-change-their-mind-1m0c</link>
      <guid>https://dev.to/emilywoodsnyc/amazon-interview-question-count-the-votes-now-let-everyone-change-their-mind-1m0c</guid>
      <description>&lt;h3&gt;
  
  
  One voter, two browser tabs, and the follow ups that turn a simple counter into a system design problem.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcak275m783nt7omiprvd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcak275m783nt7omiprvd.png" alt="One voter uses two tabs to change her vote." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Maya votes for A, changes her mind, and votes for B. Her connection drops, so her phone sends the second request again.&lt;/p&gt;

&lt;p&gt;If your system now counts four votes from three people, adding more servers is going to make the wrong answer arrive faster.&lt;/p&gt;

&lt;p&gt;This is why I like this question. You can understand the product in 10 seconds, yet a perfectly respectable looking architecture can lose track of what one person actually chose.&lt;/p&gt;

&lt;p&gt;The prompt is to design a 5-minute poll for millions of concurrent voters. People can change their choices, and everyone sees results that refresh every second. It appears in an Amazon-tagged interview report. This walkthrough is my proposed design, with illustrative numbers and follow ups, not a claim about Amazon’s production architecture or an interview I attended.&lt;/p&gt;

&lt;p&gt;Let’s start with three people, because the first mistake fits comfortably on a napkin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Maya changes her mind, and the total must stay three
&lt;/h2&gt;

&lt;p&gt;Initially, Maya and Leo choose A while Nia chooses B. The totals are A = 2 and B = 1.&lt;/p&gt;

&lt;p&gt;When Maya switches to B, the correct result becomes A = 1 and B = 2. We have changed a choice, not created another voter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuaz3a8zaghpwp2t8rzv4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuaz3a8zaghpwp2t8rzv4.png" alt="Changing Maya from A to B preserves three total voters." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That gives us a rule worth writing above the diagram. &lt;strong&gt;Each eligible account contributes at most one current choice per poll.&lt;/strong&gt; For this exercise, an account is our voter identity; preventing one person from creating several accounts is a separate abuse problem.&lt;/p&gt;

&lt;p&gt;Store the current choice under the pair of poll ID and voter ID. Keep a version alongside it. A change needs to update that record, subtract from the previous option, and add to the new option as one indivisible operation.&lt;/p&gt;

&lt;p&gt;Three independent writes are not enough. If the process stops after subtracting from A, Maya can disappear from the tally. If two requests both read her old choice, they can both subtract it.&lt;/p&gt;

&lt;p&gt;For the starting design, put the voter record and affected counters in a transactional datastore. Enforce the old version as a condition of the transaction, so a change based on stale state cannot quietly succeed.&lt;/p&gt;

&lt;p&gt;Try the &lt;a href="https://prachub.com/interview-questions/design-a-real-time-voting-system-with-vote-changes-for-millions-of-concurrent-voters?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;Amazon-tagged live-voting question&lt;/a&gt; before reading further. Sketch what happens when Maya opens two tabs and submits a different choice from each. Mark the exact operation that prevents both tabs from spending the same old version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Her second tab makes the easy answer uncomfortable
&lt;/h2&gt;

&lt;p&gt;Suppose Maya currently has choice A at version 7. One tab asks to change to B using version 7. Another asks to change to C using version 7.&lt;/p&gt;

&lt;p&gt;Whichever transaction commits first advances the voter record to version 8. The other must fail its version condition. Its counter changes must fail with it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4k7fm2712uj6raz7st6i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4k7fm2712uj6raz7st6i.png" alt="Two changes based on version seven compete; only one commits." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have an important product decision. The losing tab should fetch the current choice and tell Maya that her selection changed elsewhere. It shouldn’t automatically resubmit an old intention against the new version and undo the winning request.&lt;/p&gt;

&lt;p&gt;For this proposal, latest means the latest successfully committed change. We are not pretending to know which click Maya intended last across two devices. If the product wants a different ordering rule, agree on that rule before implementing it; client timestamps alone don’t establish a trustworthy global order.&lt;/p&gt;

&lt;p&gt;AWS documents &lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis.html" rel="noopener noreferrer"&gt;all-or-nothing transactional writes in DynamoDB&lt;/a&gt;. That is one possible building block. Capacity, transaction conflicts, key design, and the scope of those guarantees still matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  A retry is not a fresh change of mind
&lt;/h2&gt;

&lt;p&gt;Let’s return to the dropped connection. Maya’s move to B committed, but the response never reached her phone.&lt;/p&gt;

&lt;p&gt;Give every intended change a stable request ID, scoped to the poll and authenticated voter. Derive voter identity from the authenticated session rather than trusting an arbitrary ID in the request. Persist its outcome with the successful vote mutation in the same transaction. A retry with that ID returns the recorded outcome rather than moving another vote.&lt;/p&gt;

&lt;p&gt;Include the original request parameters in that record, or a fingerprint of them, so reusing the same ID for different content is rejected. Keep these records for the full retry window the API promises.&lt;/p&gt;

&lt;p&gt;The request ID and voter version solve different problems. One identifies an operation we may have already completed. The other checks whether a new operation is still based on the current state.&lt;/p&gt;

&lt;p&gt;An old, previously successful request can therefore return its historical success without overwriting Maya’s newer choice. Return its resulting version too, so the interface can recognize an older response and refresh current state when needed.&lt;/p&gt;

&lt;p&gt;For a new request that selects the existing choice, keep the counters unchanged. You can still advance the version and record the result consistently. I think the important part is that a repeated selection doesn’t invent a new voter.&lt;/p&gt;

&lt;p&gt;And you know honestly, this little sequence tells me more about the design than a page full of infrastructure logos.&lt;/p&gt;

&lt;h2&gt;
  
  
  Millions of viewers create a different bottleneck
&lt;/h2&gt;

&lt;p&gt;Now give the napkin some traffic. Assume, just for sizing, three million accounts each submit one change over 300 seconds. That averages 10,000 mutations per second. Additional changes and a final-second rush make the peak higher.&lt;/p&gt;

&lt;p&gt;If those same 3Mn million viewers request results once a second, that’s three million result requests per second. Reads and writes have very different shapes, so they shouldn’t all land on the same storage path.&lt;/p&gt;

&lt;p&gt;A single counter for A can become a contention point even when voter records are distributed nicely. Split the counters into buckets and assign each voter to a stable bucket using a hash of poll ID and voter ID.&lt;/p&gt;

&lt;p&gt;Maya’s current choice and her changes always use the same bucket during the poll. The transaction adjusts that bucket’s counters, and an aggregator adds the bucket totals together. Keep the mapping fixed for the poll; changing it midstream needs a migration protocol.&lt;/p&gt;

&lt;p&gt;As an illustration, 100 evenly loaded buckets would average about 100 mutations per second each under our initial workload. That is arithmetic, not a capacity guarantee. Transaction costs, skew, bursts, and the storage engine determine whether that arrangement actually works.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F78yz0bengzfwgidfvlsn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F78yz0bengzfwgidfvlsn.png" alt="Durable vote storage feeds cached live snapshots and a separate final recount." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Publish a small result snapshot once a second and deliver it through a cache and a scalable delivery tier. Polling through shared caches or pushing through connection gateways are both candidates. Neither makes the bandwidth or fan-out disappear.&lt;/p&gt;

&lt;p&gt;Each snapshot should carry its generation time and version. During voting, we can agree that the display is a slightly delayed provisional view. An aggregate assembled from independently advancing buckets is not automatically an exact global snapshot.&lt;/p&gt;

&lt;p&gt;Maya’s own confirmed choice can appear immediately in her interface while the public totals catch up. That’s a much nicer experience than making her guess whether the button worked.&lt;/p&gt;

&lt;h2&gt;
  
  
  The poll ends, but the last screen isn’t automatically the answer
&lt;/h2&gt;

&lt;p&gt;At five minutes, the tempting shortcut is to freeze whatever the cache currently shows.&lt;/p&gt;

&lt;p&gt;Please don’t make a potentially stale display decide the winner.&lt;/p&gt;

&lt;p&gt;First define the cutoff.&lt;/p&gt;

&lt;p&gt;In this proposal, eligibility depends on admission by the server before its enforced deadline, not when someone tapped a button on their phone.&lt;/p&gt;

&lt;p&gt;Admission needs an authoritative policy for time and clock error; unrelated machines independently trusting their local clocks is not a complete closing protocol.&lt;/p&gt;

&lt;p&gt;Then close admission and establish a barrier across the write path. Every request admitted before the cutoff must reach a terminal outcome, and no later request may sneak in.&lt;/p&gt;

&lt;p&gt;Closing a webpage timer does none of that.&lt;/p&gt;

&lt;p&gt;After the barrier is complete, recount the durable current choice records using a consistent view. Count each eligible voter once, compare with the maintained counters, and publish a versioned final result. If admitted work or a storage partition is unresolved, show that the result is being finalized rather than declaring the current cache exact.&lt;/p&gt;

&lt;p&gt;That means the window for voting can end before the final result is ready. Agree on that delay as part of the product requirement. An immediate exact result during arbitrary failures is a much stronger promise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the receipt even if the scoreboard disappears
&lt;/h2&gt;

&lt;p&gt;A success response must follow the durable commit of the vote and request outcome under the storage system’s stated failure guarantees. A fast write to a disposable cache is not enough.&lt;/p&gt;

&lt;p&gt;In this design, the live cache is replaceable. If it disappears, rebuild snapshots from durable state. For an audit trail, an append-only change record can be written in the same transaction as the vote mutation. Don’t acknowledge a vote and hope a separate history write succeeds afterward.&lt;/p&gt;

&lt;p&gt;During a partial outage, healthy partitions may continue accepting changes where the durability and deadline rules can still be enforced. If a partition cannot meet those rules, return a clear retryable failure instead of promising that an unprotected vote was accepted.&lt;/p&gt;

&lt;p&gt;We can aim for high availability without claiming that every possible failure leaves every guarantee intact.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4ut6ycepp36aia3lew5b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4ut6ycepp36aia3lew5b.png" alt="Five voting failure scenarios and their expected outcomes." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For practice, walk through the five cases in that table with a friend. After each one, say what the voter sees, what is durably recorded, and whether the displayed total is provisional or final.&lt;/p&gt;

&lt;p&gt;That’s the progression I want from an interview answer.&lt;/p&gt;

&lt;p&gt;Begin with a choice one person makes,&lt;br&gt;&lt;br&gt;
protect it through a retry and a race,&lt;br&gt;&lt;br&gt;
then scale the parts that actually need scaling.&lt;/p&gt;

&lt;p&gt;If you can explain why Maya still counts exactly once after changing her mind twice, your architecture has something solid underneath all those boxes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
    </item>
    <item>
      <title>System Design Interviews: When Is a Monolith the Better Answer?</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Tue, 01 Dec 2026 05:56:43 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/system-design-interviews-when-is-a-monolith-the-better-answer-3d7</link>
      <guid>https://dev.to/emilywoodsnyc/system-design-interviews-when-is-a-monolith-the-better-answer-3d7</guid>
      <description>&lt;h3&gt;
  
  
  A practical way to choose service boundaries without turning every feature into another deployment.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhu584w1n26haa28741ni.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhu584w1n26haa28741ni.png" alt="Choosing between one modular application and independently operated services." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You draw one application and one database,&lt;br&gt;&lt;br&gt;
then feel a tiny urge to apologize for the diagram.&lt;/p&gt;

&lt;p&gt;Surely a serious system design answer needs more boxes. Maybe a separate service for reviews, another for favorites, and something with an impressive name between them.&lt;/p&gt;

&lt;p&gt;I think that little moment deserves attention, because making a diagram look more experienced can quietly make the system harder to operate.&lt;/p&gt;

&lt;p&gt;A monolith is an application deployed as a unit. Microservices split responsibilities into separately deployable services. Neither label tells us whether the code is organized well, whether the database is overloaded, or whether the team can recover from a bad release.&lt;/p&gt;

&lt;p&gt;So let’s work through the decision with a small catalog application. By the end, you’ll have a defensible starting design, a reason to change it, and an answer for the uncomfortable follow-up about what happens when a service call times out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with the changes that belong together
&lt;/h2&gt;

&lt;p&gt;Imagine a four-person team building a catalog where people browse items, save favorites, and leave reviews.&lt;/p&gt;

&lt;p&gt;For this exercise, assume those engineers share a release schedule and that their current workload fits comfortably on the database.&lt;/p&gt;

&lt;p&gt;These are practice assumptions,&lt;br&gt;&lt;br&gt;
not a description of a particular company’s system.&lt;/p&gt;

&lt;p&gt;One application is a reasonable starting point.&lt;/p&gt;

&lt;p&gt;Inside it, catalog, reviews, and favorites can still have distinct interfaces and clear ownership of their data.&lt;/p&gt;

&lt;p&gt;Catalog code owns item updates.&lt;br&gt;&lt;br&gt;
Review code owns reviews.&lt;br&gt;&lt;br&gt;
Favorites code owns saved items.&lt;/p&gt;

&lt;p&gt;Another module asks through an agreed interface instead of reaching into a table and changing whatever seems convenient.&lt;/p&gt;

&lt;p&gt;That discipline matters even when everyone shares the same repository and database. Putting files in three folders doesn’t establish a boundary if every folder can rewrite everyone else’s state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fht1q5g09hazd4mmo3ioc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fht1q5g09hazd4mmo3ioc.png" alt="Catalog, reviews and favorites have distinct write ownership within one application and PostgreSQL database." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now add one original requirement. Publishing an item must also create its audit entry, and the product must never expose a published item without that entry.&lt;/p&gt;

&lt;p&gt;With both writes in the same transactional database, the application can commit them together. Keep the database transaction short, and make the publication path use it consistently. An unrelated network call doesn’t belong inside that promise just because it happens in the same function.&lt;/p&gt;

&lt;p&gt;If those writes move behind separate services with independent databases, preserving the same guarantee becomes a different problem.&lt;/p&gt;

&lt;p&gt;You may need a distributed transaction, or you may change the workflow so an item remains pending until required work completes. Either choice needs an explanation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before separating two responsibilities,&lt;br&gt;&lt;br&gt;
ask which outcomes must succeed or fail together.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For another setting, try this &lt;a href="https://prachub.com/interview-questions/scale-a-service-you-just-built-schema-trade-offs-new-features-indexes-and-search?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;Intuit service scaling exercise&lt;/a&gt;. Sketch the first version with one application, then choose the requirement that would make you introduce a new boundary. The company tag comes from a reported interview; the four-person team and audit example here are my practice additions.&lt;/p&gt;

&lt;h2&gt;
  
  
  One deployment doesn’t mean one machine
&lt;/h2&gt;

&lt;p&gt;This is where the conversation gets more interesting, because people sometimes use monolith as shorthand for a single server that can never grow.&lt;/p&gt;

&lt;p&gt;A stateless application can run multiple replicas behind a load balancer. All those replicas can run the same deployable application.&lt;/p&gt;

&lt;p&gt;You still need to handle shared state, database connections, and the actual capacity of storage, but you haven’t become a microservices architecture simply by adding instances.&lt;/p&gt;

&lt;p&gt;Suppose a listing endpoint slows down. First inspect where its time goes. An expensive query, missing index, or unnecessary repeated lookup will not automatically improve when you place the same operation behind another HTTP endpoint.&lt;/p&gt;

&lt;p&gt;Likewise, CPU heavy image processing may justify a separate worker pool before it justifies splitting every business module into an independently owned service. Workers can have their own resource limits and scale separately while sharing code and a release process with the application.&lt;/p&gt;

&lt;p&gt;I like making that distinction explicit. Like we can separate execution resources without pretending we’ve also solved service ownership, data contracts, and independent releases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fla9dmkoy70bgct2cihsm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fla9dmkoy70bgct2cihsm.png" alt="Match a slow query to query analysis, CPU-heavy work to worker isolation, and independent releases to a possible service boundary." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Draw the failure before celebrating the split
&lt;/h2&gt;

&lt;p&gt;Let’s consider extracting reviews. Give that service ownership of review writes and suppose the catalog calls it over the network.&lt;/p&gt;

&lt;p&gt;The review service saves a submission, but its response disappears before the caller receives it. The caller times out.&lt;/p&gt;

&lt;p&gt;Did the write fail? We don’t know yet, and that’s the important part. The remote system may have committed successfully even though the caller never received confirmation.&lt;/p&gt;

&lt;p&gt;Retrying blindly could create a second review. Giving the operation a stable identifier, checking whether it already completed, and returning its recorded result can make retries safer. The service must actually enforce that behavior; adding an ID to a request isn’t enough by itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvm43kxfn55jgqrk0etb8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvm43kxfn55jgqrk0etb8.png" alt="A review write commits, its response is lost, and the caller times out without knowing whether it succeeded." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now ask what the browsing page does while reviews are unavailable. If the product allows it, the page might show the item with a clear reviews-unavailable state. It must not turn that missing response into a made-up zero-star rating.&lt;/p&gt;

&lt;p&gt;This is also why splitting services doesn’t guarantee failure isolation. If every catalog request waits synchronously for five other services, one slow dependency can still hold up the whole page. Timeouts, bounded concurrency, and an intentional degraded response become part of the design.&lt;/p&gt;

&lt;p&gt;None of that makes microservices bad. It gives the new boundary a price we can discuss honestly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make independence concrete enough to test
&lt;/h2&gt;

&lt;p&gt;Now change our assumptions. A separate reviews team needs frequent releases, and shipping the catalog application repeatedly blocks those releases. Review processing also needs a different scaling profile. The boundary has become stable enough that the two teams can describe what crosses it.&lt;/p&gt;

&lt;p&gt;That is a much stronger case for extraction than having several nouns in the product description.&lt;/p&gt;

&lt;p&gt;Before approving the split, write down four practical agreements.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data ownership.&lt;/strong&gt; The reviews service owns review writes. Other services don’t secretly update its tables and then call the architecture independent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compatibility.&lt;/strong&gt; New and old clients can coexist during deployment, with a plan for changing the API or event schema.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Failure behavior.&lt;/strong&gt; Callers know whether to retry, how to identify a repeated operation, and what users see during an outage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Operations.&lt;/strong&gt; Someone owns deployment, alerts, capacity, and recovery for the new service.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sharing a database server is not the same as sharing write ownership. Conversely, putting data on different servers doesn’t remove coupling if each release still requires all teams to deploy together.&lt;/p&gt;

&lt;p&gt;Martin Fowler’s &lt;a href="https://martinfowler.com/bliki/MonolithFirst.html" rel="noopener noreferrer"&gt;Monolith First&lt;/a&gt; discusses the difficulty of discovering stable service boundaries early and the overhead of operating multiple services. He also makes clear that the advice is not unanimous. I find that more useful than treating either architecture as a rule everyone must follow.&lt;/p&gt;

&lt;p&gt;For a team with established boundaries, independent owners, and mature deployment tooling, starting with several services may be sensible. Security or regulatory isolation requirements may also change the choice before traffic becomes interesting. Ask about those constraints rather than assuming every project starts like our little catalog.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rehearse the decision, then change your mind on purpose
&lt;/h2&gt;

&lt;p&gt;Try a fifteen-minute practice round with a blank page. This is a rehearsal structure, not a hiring rubric.&lt;/p&gt;

&lt;p&gt;Spend five minutes drawing a modular application and naming one operation that needs an atomic database update. Use the next five to introduce a real pressure, such as independent releases or a resource-heavy workload. Spend the final five explaining the new failure mode and the condition that would make the change worthwhile.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwgi0bs05iiuc8hsnklfj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwgi0bs05iiuc8hsnklfj.png" alt="Four prompts for defending a boundary: atomic changes, a concrete requirement, operational costs and reconsideration evidence." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your explanation can sound natural while still being precise.&lt;/p&gt;

&lt;p&gt;With one team and closely coordinated writes, I prefer a modular monolith for this version. It keeps deployment and transactional changes simpler. I’ll reconsider the reviews boundary when independent releases or measured resource contention create a specific problem. If we extract it, review ownership, safe retries, and the browsing fallback have to move into the design too.&lt;/p&gt;

&lt;p&gt;Notice how that answer gives the interviewer somewhere useful to push. They can change the team structure, the failure requirement, or the workload, and you can reason forward instead of defending your original diagram at all costs.&lt;/p&gt;

&lt;p&gt;You don’t need to apologize for a small architecture. But you do need to explain what it protects, where it runs out of room, and what you will do when the evidence changes.&lt;/p&gt;

&lt;p&gt;That’s an answer worth practicing before drawing another box.&lt;/p&gt;

&lt;p&gt;If you are actively preparing for interviews, stay updated with more such informative solutions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Stop Reading the Codebase From the Top. Follow One Request.</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Mon, 30 Nov 2026 17:05:20 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/stop-reading-the-codebase-from-the-top-follow-one-request-2ak0</link>
      <guid>https://dev.to/emilywoodsnyc/stop-reading-the-codebase-from-the-top-follow-one-request-2ak0</guid>
      <description>&lt;h3&gt;
  
  
  A small map can get you to the bug faster than a very impressive tour of every folder.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu5ypwyp1er8x4k6o27a8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu5ypwyp1er8x4k6o27a8.png" alt="An engineer traces one request from a form through the API to the database instead of exploring fifty files at random." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You open an unfamiliar project and immediately start negotiating with yourself. Maybe you should understand the architecture first. Maybe the README explains everything. Maybe opening just a few more files will make the whole thing click.&lt;/p&gt;

&lt;p&gt;Now 20 mins later, you know where the icons live, but you still can’t explain what happens when someone presses Submit.&lt;/p&gt;

&lt;p&gt;That is the moment I prefer to make the task smaller. Pick the behavior you need to understand and follow it from the user’s action to the result. Let the project reveal itself along that path instead of treating the file tree as a reading list.&lt;/p&gt;

&lt;p&gt;This works as a practice routine for a debugging interview, a new team’s service or a side project you have not touched in months. You are building enough understanding to investigate one behavior, with a place to record everything you have not confirmed yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with something a person can actually do
&lt;/h2&gt;

&lt;p&gt;Imagine a movie review app with almost 50 files. Someone reports that users can submit more reviews than the limit allows. The file count and the rule below are invented for this walkthrough.&lt;/p&gt;

&lt;p&gt;For our small exercise, one authenticated user may submit 3 successful reviews in a fixed 1 minute window. A fourth attempt during that window must be rejected without saving another review. The next window starts a fresh allowance.&lt;/p&gt;

&lt;p&gt;Before reading implementation details, write that expectation in your notes. It gives you something to compare with the program instead of allowing the current code to define what correct means.&lt;/p&gt;

&lt;p&gt;Now locate the review form. Follow its submit handler to the network request, find the server route that receives it, and identify the checks and storage operation on that route.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgsycf31reggcg2pjqyad.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgsycf31reggcg2pjqyad.png" alt="A verified request path connects a review form to POST /reviews, a limiter, a handler and the database." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The map starts as a hypothesis. Perhaps the limiter runs inside the handler rather than before it. Perhaps a gateway rejects the request before the application sees it. Update the drawing when you find evidence; do not squeeze the code into the architecture you expected.&lt;/p&gt;

&lt;p&gt;For practice with a similar unfamiliar-project setup, the &lt;a href="https://prachub.com/interview-questions/debug-rate-limiting-and-inappropriate-word-checks-in-a-full-stack-movie-review-app?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;Amazon-movie review debugging&lt;/a&gt; question describes broken rate limiting and comment validation. Try outlining the request path and the questions you need answered before reading the guidance. It is a reported assessment scenario, not an official Amazon question bank, and our three review rule is an illustrative choice rather than a requirement from that listing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Search for the thing you just observed
&lt;/h2&gt;

&lt;p&gt;Suppose the browser sends &lt;code&gt;POST /reviews&lt;/code&gt;. Search for that route or a distinctive part of the request payload. If the address is assembled from several pieces, follow the client helper that constructs it.&lt;/p&gt;

&lt;p&gt;Once you find the route registration, trace the handlers it actually attaches. A function named &lt;code&gt;rateLimit&lt;/code&gt; elsewhere in the repository does not prove this request uses it. Follow the reference from the entry point rather than admiring a promising filename.&lt;/p&gt;

&lt;p&gt;I like keeping a small note beside the editor with three columns. Record what you observed, what might explain it and the next check that could distinguish the possibilities.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdpxm11c24lhrss92nu6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdpxm11c24lhrss92nu6h.png" alt="An investigation table separates observed behavior, possible causes and the next check rather than treating guesses as facts." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, the fourth review being accepted is an observation. The limiter never running is a possible explanation. Tracing the route wiring can support or reject that explanation.&lt;/p&gt;

&lt;p&gt;If the limiter does run, move on. Check which user key it receives and where its counter comes from. Finding that the counter is always one suggests a different investigation than finding that the limiter is never called.&lt;/p&gt;

&lt;p&gt;This is a surprisingly calming way to work because each opened file has a reason to be open. You are answering a question, not hoping familiarity will eventually arrive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ask AI for directions you can check
&lt;/h2&gt;

&lt;p&gt;A coding assistant can help locate a route, collect call sites and summarize nearby tests. Give it a bounded navigation task before asking it to repair the entire application.&lt;/p&gt;

&lt;p&gt;One useful request is to trace the review submission from its UI entry point to persistence, include file paths and symbols for each step, separate confirmed calls from guesses, and make no edits yet.&lt;/p&gt;

&lt;p&gt;Then verify the links in that chain. Does the route registration call the function it named? Is the test importing that implementation? Does the code belong to the active application, or an old example directory nobody runs?&lt;/p&gt;

&lt;p&gt;Willy Tarreau’s recent &lt;a href="https://www.haproxy.com/blog/on-the-use-of-ai-based-tools-to-find-bugs-in-open-source-software" rel="noopener noreferrer"&gt;account of AI assisted bug reports at HAProxy&lt;/a&gt; describes the burden of reports missing usable reproduction details and even the tested commit. That is a useful reminder for everyday debugging too. A convincing explanation becomes much more helpful when someone else can follow it back to the same code and behavior.&lt;/p&gt;

&lt;p&gt;Save the version you inspected and the command you ran. Ask the assistant to identify missing context rather than filling it with a plausible architecture. Sometimes the most valuable answer is that the path crosses a service whose code is not in this repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watch where the state survives
&lt;/h2&gt;

&lt;p&gt;Back in our review app, imagine the route does call the limiter, but creates a fresh counter for every request. Each submission gets a brand-new memory of the world. Naturally, every review looks like the first one.&lt;/p&gt;

&lt;p&gt;To investigate that hypothesis, inspect the counter’s initialization and lifetime. In a local development run, observe the user key and count across repeated requests without logging private review text or credentials. Keep the requests inside the same test window so a legitimate reset does not confuse the result.&lt;/p&gt;

&lt;p&gt;If the counter is recreated on every call, you have found a concrete lifetime mismatch. Moving it somewhere that survives requests may address the single process exercise, but that does not automatically make it correct across several server instances. Keep those claims separate.&lt;/p&gt;

&lt;p&gt;You have also learned something useful about the codebase. You now know where the route is wired, where user identity enters, where state lives and where a review gets stored. That is a meaningful chunk of architecture learned through one actual behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give yourself permission to leave files unread
&lt;/h2&gt;

&lt;p&gt;The recommendation engine may be beautifully written. The admin dashboard may have fascinating abstractions. Neither deserves your next ten minutes merely because its folder appears above the review API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fawe3gbtqv0331xse19e5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fawe3gbtqv0331xse19e5.png" alt="The review request path stays in focus while recommendations, billing and the admin dashboard remain outside the current investigation." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keep a small parking list for questions that matter later. Add an item when you notice a shared dependency or a possible second bug, then return to the current path unless that finding changes your immediate investigation.&lt;/p&gt;

&lt;p&gt;This is not permission to ignore dependencies. Follow shared middleware, helpers and downstream calls when the request actually uses them. The boundary is evidence, not a predetermined number of files you are allowed to read.&lt;/p&gt;

&lt;h2&gt;
  
  
  Leave the next person a smaller mystery
&lt;/h2&gt;

&lt;p&gt;Before considering the task finished, turn your map into a short handoff. Include the entry point, the behavior you expected, the observation that contradicted it, the change you made and the checks you ran.&lt;/p&gt;

&lt;p&gt;For our example, verify that the first three valid reviews are saved, the fourth is rejected without a write, a different user has a separate allowance and the next window permits a fresh request. Control time in the test instead of waiting a real minute and hoping the boundary behaves.&lt;/p&gt;

&lt;p&gt;Also check the surrounding behavior that your change could affect. Fixing the limiter should not accidentally bypass comment validation or make the success response describe a review that was never stored.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flcnb6m9vmi5xna06wiea.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flcnb6m9vmi5xna06wiea.png" alt="A handoff notebook records the entry point, expected rule, observed evidence and smallest verified change." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you cannot run a dependency, say exactly which part remains unverified. A clear limit is more useful to a teammate than a cheerful everything-looks-good summary.&lt;/p&gt;

&lt;p&gt;I prefer finishing with one explainable path over a vague sense that I have explored the repository. Tomorrow, another request can teach you another part of the system.&lt;/p&gt;

&lt;p&gt;For your next unfamiliar project, find the button, message or command that starts the behavior you care about. Follow it until you can explain where the result comes from. The folders will still be there when you need them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>debugging</category>
    </item>
    <item>
      <title>System Design Interviews: When Do You Actually Need Redis or Kafka?</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Sun, 29 Nov 2026 05:15:11 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/system-design-interviews-when-do-you-actually-need-redis-or-kafka-4o0</link>
      <guid>https://dev.to/emilywoodsnyc/system-design-interviews-when-do-you-actually-need-redis-or-kafka-4o0</guid>
      <description>&lt;h3&gt;
  
  
  A practical way to defend your architecture, using one small AI report service.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhccqjj2dkvovc6ilkxiw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhccqjj2dkvovc6ilkxiw.png" alt="An engineer weighs Redis for faster reads and Kafka for replayable events." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An interviewer points at Redis and asks what happens if you remove it.&lt;/p&gt;

&lt;p&gt;You know Redis is fast. You know Kafka handles events. You know PostgreSQL stores data. Somehow, none of that explains why this particular application needs all three.&lt;/p&gt;

&lt;p&gt;Honestly, this is where system design preparation can get a little sneaky. Studying more diagrams starts to feel like progress, even when the hardest part is still choosing what to leave out.&lt;/p&gt;

&lt;p&gt;I prefer a smaller challenge. Pick one application, give it a few real constraints, and make every new component solve a problem you can name.&lt;/p&gt;

&lt;p&gt;We’ll use an AI report generator because it has familiar ingredients without requiring a giant architecture. Users submit documents, a worker generates a report, and the app shows when it is ready. The AI step makes the job slow; it doesn’t automatically make the rest of the system exotic.&lt;/p&gt;

&lt;p&gt;By the end, you’ll have a way to explain when a database is enough, when a cache helps, and when an event log becomes worth its operational cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with the promise you are making
&lt;/h2&gt;

&lt;p&gt;For this practice example, assume 100 report requests per minute, an average processing time of 20 seconds, and a progress screen that can be five seconds behind. Reports are private. Once a request is accepted, a worker crash must not make it disappear.&lt;/p&gt;

&lt;p&gt;Those are invented interview assumptions, so change them when the interviewer gives you something different.&lt;/p&gt;

&lt;p&gt;Already, the numbers tell us something useful. At a steady arrival rate of roughly 1.67 jobs per second, with 20 seconds of active processing per job, we need about 33 jobs in progress on average just to keep up. That’s concurrency, not 33 physical servers, and it leaves no headroom for bursts or slower jobs.&lt;/p&gt;

&lt;p&gt;Adding Redis doesn’t shorten a model call. Adding Kafka doesn’t increase the model provider’s quota. Before drawing either, check which resource actually limits throughput.&lt;/p&gt;

&lt;p&gt;For a first design, an API can record a job in PostgreSQL and return its ID after the transaction commits. A separate worker claims pending work, generates the report, and records the result. Large documents and report files can live in object storage, with their locations recorded in the database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The useful question is whether accepted work survives a failure, not whether the picture looks sufficiently distributed.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc1c6sx23tl2mn3jxr411.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc1c6sx23tl2mn3jxr411.png" alt="A baseline report service records jobs in PostgreSQL and uses separate workers with recoverable claims." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the database version a fair chance
&lt;/h2&gt;

&lt;p&gt;A jobs table needs more than a status column. Record the job’s owner, input version, attempt count, and the time until which a worker owns its claim. Commit the claim in a short transaction, then do the expensive work outside that transaction.&lt;/p&gt;

&lt;p&gt;If a worker disappears, its claim can expire so another worker can retry. A claim token or version prevents an old worker from overwriting a newer attempt’s result. It doesn’t undo an external action the old worker already performed, so those effects need their own duplicate protection.&lt;/p&gt;

&lt;p&gt;PostgreSQL’s &lt;a href="https://www.postgresql.org/docs/current/sql-select.html" rel="noopener noreferrer"&gt;SKIP LOCKED documentation&lt;/a&gt; describes avoiding contention among consumers of a queue-like table. That is a useful building block, not a complete job system. You still own retries, recovery, cleanup, fairness, and monitoring.&lt;/p&gt;

&lt;p&gt;This design has limits. Polling and frequent updates can contend with other database work. A managed queue may be preferable because the team already operates one, needs better workload isolation, or doesn’t want to maintain those mechanics.&lt;/p&gt;

&lt;p&gt;But 100 requests per minute alone does not prove that a separate broker is required. Measure the actual workload and explain the operational trade-off.&lt;/p&gt;

&lt;p&gt;For a different setting, try this &lt;a href="https://prachub.com/interview-questions/design-a-daily-slowest-query-report-for-bigquery-with-fixed-day-windows?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;Google tagged daily query report design question&lt;/a&gt;. Before drawing a streaming pipeline, decide whether the reader needs a result once a day or an answer that changes continuously. Write down how that single requirement changes your architecture. The company tag comes from the reported question, not an official interview specification.&lt;/p&gt;

&lt;h2&gt;
  
  
  Redis earns its place when repeated reads become a problem
&lt;/h2&gt;

&lt;p&gt;Now imagine the progress screen gets popular. Thousands of users keep checking the same small set of jobs, and measurements show those reads are hurting database latency.&lt;/p&gt;

&lt;p&gt;A cache becomes a reasonable candidate because we have both a repeated workload and permission to return slightly stale information.&lt;/p&gt;

&lt;p&gt;Suppose the screen receives 1,000 requests per second. With a 95% cache hit rate, about 50 requests per second still need the underlying read. That is a planning estimate, not a performance promise. If keys expire together or every request asks for a different job, the database can see a very different load.&lt;/p&gt;

&lt;p&gt;Start by checking the query, index, and polling frequency. If those are already sensible, Redis can store a short-lived progress view while PostgreSQL remains authoritative.&lt;/p&gt;

&lt;p&gt;Then separate two questions that often get bundled together.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A progress bar can show the previous processing state for a few seconds if the product accepts that delay.&lt;/li&gt;
&lt;li&gt;A download permission check cannot rely on that same allowance if access revocation must take effect immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyfea7tl07hmtyc2yhoy8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyfea7tl07hmtyc2yhoy8.png" alt="Progress may tolerate five-second staleness while download authorization checks current permissions." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the progress view, a short TTL and invalidation on update can be a starting design. Neither magically eliminates races. An older read can finish after an update and repopulate stale data, so strict freshness needs stronger coordination or a different read path.&lt;/p&gt;

&lt;p&gt;Also explain the miss path. If Redis becomes unavailable, letting every request hit PostgreSQL can turn one outage into two. Back off polling, coalesce repeated loads, or shed nonessential progress requests so the fallback stays within capacity.&lt;/p&gt;

&lt;p&gt;Now Redis has a defensible job. It reduces repeated read work under an explicit freshness contract. It is not an architectural good-luck charm.&lt;/p&gt;

&lt;h2&gt;
  
  
  Kafka earns its place when consumers need their own history
&lt;/h2&gt;

&lt;p&gt;Next, change the product rather than simply multiplying the traffic number.&lt;/p&gt;

&lt;p&gt;Completed reports now feed search indexing, analytics, and notifications. Each team deploys independently. Analytics needs to rebuild its derived results after a bug, without generating all the reports again.&lt;/p&gt;

&lt;p&gt;That is a stronger reason to consider an event log. We want independent consumers and retained events they can read again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kafka.apache.org/intro/" rel="noopener noreferrer"&gt;Kafka’s introduction&lt;/a&gt; explains that consuming an event does not delete it. Retention determines how long it remains available, and ordering is guaranteed within a partition rather than across an entire topic.&lt;/p&gt;

&lt;p&gt;Separate consumer groups can maintain independent progress. Choose a partition key that matches the ordering you need, such as a job ID, and decide how much history to retain.&lt;/p&gt;

&lt;p&gt;Kafka is one option for those requirements, not the only possible implementation. A small system might manage with an event table or another managed service. The point is to justify replay and independent consumption before choosing the product.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm9wg4v0byzy1fpo7l9h1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm9wg4v0byzy1fpo7l9h1.png" alt="A transactional outbox feeds an event log with independent search, analytics and notification consumers." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There’s still an awkward gap between marking a job complete in PostgreSQL and publishing its event.&lt;/p&gt;

&lt;p&gt;If the database commit succeeds but publication fails, downstream consumers may never hear about it. One approach is to write the completion and an outbox record in the same database transaction, then let a relay publish committed outbox records.&lt;/p&gt;

&lt;p&gt;A relay can publish twice if it crashes before recording its progress. Consumers therefore need duplicate handling, and an email provider doesn’t become exactly-once merely because Kafka appears upstream.&lt;/p&gt;

&lt;p&gt;This is the part worth discussing in an interview. A new component solves one problem and creates responsibilities you must be able to explain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practice by changing one requirement at a time
&lt;/h2&gt;

&lt;p&gt;Keep the original diagram on one page. Beside it, write the reason for each component and the condition that would make you reconsider it.&lt;/p&gt;

&lt;p&gt;For PostgreSQL, that might be durable job state with transactional updates. For Redis, it might be measured repeated-read pressure plus acceptable staleness. For Kafka, it might be independently consumed events with a defined replay window.&lt;/p&gt;

&lt;p&gt;Then give yourself three changes, separately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First, progress updates must be immediate.&lt;/strong&gt; Revisit caching and delivery semantics. A shorter TTL alone doesn’t establish immediate freshness.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next, report creation jumps tenfold.&lt;/strong&gt; Estimate required processing concurrency and check provider quotas, queue wait time, and database contention before adding infrastructure by habit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Finally, analytics must recompute last week’s results.&lt;/strong&gt; Check whether the retained events contain the inputs needed for that computation. Replay cannot recover data you never recorded, and rerunning an AI model is not the same as replaying a stored completion event.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1ko8gvgbs991vfrml43f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1ko8gvgbs991vfrml43f.png" alt="Four prompts for each architecture choice: requirement, evidence, cost and revisit trigger." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give yourself twenty minutes for that exercise. Spend the first five agreeing on requirements, the next five sketching a baseline, and the remaining ten changing one assumption and defending the resulting edits.&lt;/p&gt;

&lt;p&gt;A useful answer names the requirement, the evidence, the extra failure mode, and the trigger for revisiting the decision. You can use those four prompts even when the technology is completely unfamiliar.&lt;/p&gt;

&lt;p&gt;I like this kind of practice because it gives you somewhere to go when an interviewer pushes back. You don’t have to defend a memorized picture. You can return to the requirement and reason forward with them.&lt;/p&gt;

&lt;p&gt;Before saving another architecture diagram, try removing one box and explaining what breaks. If nothing meaningful changes, you may have found the most useful part of your next practice session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>ai</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>System Design Interview: Your AI Agent Has a $10 Budget. Who Enforces It?</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Sun, 29 Nov 2026 05:14:39 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/system-design-interview-your-ai-agent-has-a-10-budget-who-enforces-it-2bac</link>
      <guid>https://dev.to/emilywoodsnyc/system-design-interview-your-ai-agent-has-a-10-budget-who-enforces-it-2bac</guid>
      <description>&lt;h3&gt;
  
  
  Two workers, one balance, and a surprisingly expensive gap between checking and spending.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7wbdk0f3j0vyzcwh3bnq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7wbdk0f3j0vyzcwh3bnq.png" alt="An AI agent sends two six-dollar requests through one budget gate under a ten-dollar limit." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give an AI agent a $10 budget and it sounds like a very small system design problem. Keep a counter, subtract each charge, and stop when the money runs out.&lt;/p&gt;

&lt;p&gt;Then let the agent do two things at once.&lt;/p&gt;

&lt;p&gt;Both workers see $10 available. Both decide that a $6 operation is affordable. Both send the request, and now your beautifully documented budget has become a $12 bill.&lt;/p&gt;

&lt;p&gt;Nobody had to ignore an instruction. Each worker made a reasonable decision using information that stopped being safe the moment another worker used it too.&lt;/p&gt;

&lt;p&gt;This is the kind of interview exercise I like because you can feel the bug before anybody names a database or draws six services. Let’s build a budget that actually participates in the decision to spend.&lt;/p&gt;

&lt;p&gt;We’ll use an original practice scenario, not a reported company question. The dollar amounts are deliberately simple examples, not real model prices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start by defining what the $10 covers
&lt;/h2&gt;

&lt;p&gt;For this exercise, give one agent run a fixed budget of $10. Every paid model or tool call must pass through a service we control. Workers cannot call those providers directly with their own credentials.&lt;/p&gt;

&lt;p&gt;Also assume we can put a trustworthy maximum charge on each authorized operation. We’ll return to that assumption because it is doing quite a lot of work.&lt;/p&gt;

&lt;p&gt;Three amounts matter.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Spent&lt;/strong&gt; is the cost we have confirmed and settled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reserved&lt;/strong&gt; is money committed to operations whose final costs are not settled yet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Available&lt;/strong&gt; is the budget minus both spent and reserved.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rule is that spent plus reserved must never exceed the budget. Counting only completed calls leaves every in-flight call spending money that still looks available.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5wdau55uszctlugo33vh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5wdau55uszctlugo33vh.png" alt="Two workers independently read ten dollars and spend six each, exceeding the shared budget by two dollars." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A notification after the balance crosses $10 might help someone investigate. It cannot stop a request that has already been accepted elsewhere. The admission decision needs to happen before dispatch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reserve the money before asking the provider
&lt;/h2&gt;

&lt;p&gt;Worker A requests a $6 reservation. The budget service checks the available amount and creates that reservation as one atomic operation.&lt;/p&gt;

&lt;p&gt;After it commits, the ledger shows $0 spent, $6 reserved, and $4 available. Worker B’s $6 request now fails the check. It can wait, choose a cheaper permitted operation, or return the useful work already completed.&lt;/p&gt;

&lt;p&gt;Please don’t make the fallback another unbounded loop that keeps asking for money. We have enough problems already.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F25al2g3054a7gg8pn30y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F25al2g3054a7gg8pn30y.png" alt="An atomic six-dollar reservation leaves four dollars available and blocks another six-dollar request." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One implementation can use a database transaction that locks the run’s budget row, checks for an existing operation ID, verifies available funds, and creates the reservation while updating the reserved total. Every writer must follow the same locking protocol. Commit before making the network call so a slow provider doesn’t hold the database lock.&lt;/p&gt;

&lt;p&gt;Store a unique operation ID within the run, plus the requested maximum, input fingerprint, state, and provider reference when available. If the caller repeats the same operation after losing our response, return its existing reservation. Reject reuse of the same ID with different inputs.&lt;/p&gt;

&lt;p&gt;For a useful companion exercise, try the reserved-transfer stage of this &lt;a href="https://prachub.com/interview-questions/design-a-banking-ledger-with-accepted-transfers-and-account-merges?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;Airbnb-tagged banking ledger question&lt;/a&gt;. Trace the available balance before and after a transfer is accepted, then explain which money is merely held. It is a reported interview exercise; our AI-budget example here is separate.&lt;/p&gt;

&lt;p&gt;That distinction between held and settled money is the foundation. Now we need to handle the part that happens outside our database.&lt;/p&gt;

&lt;h2&gt;
  
  
  A timeout does not give the money back
&lt;/h2&gt;

&lt;p&gt;Suppose A reserved $6, sent the request, and then lost its connection.&lt;/p&gt;

&lt;p&gt;We know our client stopped waiting. We don’t yet know whether the provider finished the operation, charged for part of it, or did nothing at all.&lt;/p&gt;

&lt;p&gt;AWS’s &lt;a href="https://builder.aws.com/content/3EumjoZascWd1oZiEgL8ORlv3qE/timeouts-retries-and-backoff-with-jitter" rel="noopener noreferrer"&gt;discussion of timeouts and retries&lt;/a&gt; makes this distinction explicit. Failure to receive a response does not prove that a side effect never happened.&lt;/p&gt;

&lt;p&gt;So the reservation stays in an unresolved state while we reconcile it. Query the provider using its operation reference when supported, or wait for authoritative usage information. An age alert can flag a stuck reservation for investigation, but age alone is not evidence that releasing it is safe.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw7rk6lassmgs95fdbs9s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fw7rk6lassmgs95fdbs9s.png" alt="Settle a confirmed charge, release confirmed unused funds, and keep an unknown outcome reserved." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the confirmed final charge is $4, settle the reservation atomically by moving $4 into spent and removing the $6 hold. Available funds become $6. If we can establish that no charge happened and no further dispatch can occur, release the entire hold.&lt;/p&gt;

&lt;p&gt;A repeated settlement notification must not perform that transition twice. Match it to the operation, verify the state and amount, and return the recorded outcome if it has already been applied.&lt;/p&gt;

&lt;p&gt;Notice the trade-off. Keeping uncertain funds reserved can temporarily stop useful work. Releasing them optimistically can break the budget. For a hard spending cap, I prefer making that interruption visible rather than quietly turning uncertainty into free money.&lt;/p&gt;

&lt;h2&gt;
  
  
  One reservation must not authorize two paid calls
&lt;/h2&gt;

&lt;p&gt;An internal operation ID prevents duplicate reservations. It does not automatically stop two network requests from creating two charges.&lt;/p&gt;

&lt;p&gt;Use the provider’s idempotency mechanism when it supports the required operation and guarantees. A retry must preserve the same provider key and request meaning, within that mechanism’s documented limits.&lt;/p&gt;

&lt;p&gt;Without that protection, a worker that crashes around dispatch leaves an awkward uncertainty. Don’t blindly send the request again under the old reservation. Resolve the original outcome, or treat a further potentially billable attempt as additional exposure that needs its own budget authorization.&lt;/p&gt;

&lt;p&gt;The same warning applies to expiring worker leases. An old worker may still be running after another worker takes over. Your dispatcher needs to prevent stale attempts from sending new paid requests, and it must not equate a lost lease with a refunded provider charge.&lt;/p&gt;

&lt;p&gt;For an interview, describe this boundary clearly. A database transaction protects your ledger. It cannot make an unrelated provider join that transaction.&lt;/p&gt;

&lt;h2&gt;
  
  
  The maximum charge has to mean something
&lt;/h2&gt;

&lt;p&gt;So far, $6 has represented a real upper bound, not our best guess.&lt;/p&gt;

&lt;p&gt;For a model call, that bound might require a known input size, an enforced output limit, a recorded pricing version, and allowances for every separately billable feature. For a tool, it might require an explicit maximum quantity or a fixed-price operation. Nested calls and automatic SDK retries must be included or separately authorized.&lt;/p&gt;

&lt;p&gt;Use exact monetary arithmetic with units fine enough for the provider’s prices. Integer cents are convenient for our drawings, but actual usage may need micro-units or decimal arithmetic rather than rounding each small charge to cents.&lt;/p&gt;

&lt;p&gt;If a provider cannot bound the charge, our local reservation cannot honestly guarantee an exact invoice ceiling. We can refuse that operation under a hard-cap policy, obtain an enforceable provider-side limit, or offer a clearly described soft budget instead.&lt;/p&gt;

&lt;p&gt;That is a much stronger answer than quietly replacing maximum cost with average cost and hoping nobody notices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the awkward cases before adding more architecture
&lt;/h2&gt;

&lt;p&gt;Start with a tiny ledger model and a fake provider you can pause at chosen points. Real requests cost money and make failures harder to reproduce, so keep this practice local.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy5ecn93pmh3ng35g5lzi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy5ecn93pmh3ng35g5lzi.png" alt="Four tests cover concurrent reservations, duplicate operations, duplicate settlements and uncertain provider outcomes." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run two $6 reservation requests against a $10 budget at the same time. Exactly one should succeed, and the total exposure should remain $6.&lt;/p&gt;

&lt;p&gt;Then repeat that successful operation ID. The ledger should return the original reservation without holding another $6. Repeat its settlement too, and verify that spent increases only once.&lt;/p&gt;

&lt;p&gt;Finally, simulate a timeout after dispatch. Confirm that the hold remains, another unaffordable operation is rejected, and a later confirmed $4 charge produces $4 spent, $0 reserved, and $6 available.&lt;/p&gt;

&lt;p&gt;Add a crash just before dispatch as a separate case. Releasing those funds is safe only after recovery can establish that the operation was never sent and cannot still be sent by a stale worker.&lt;/p&gt;

&lt;p&gt;These checks are small enough to explain on a whiteboard, but they force you to connect concurrency, retries, and accounting in one answer. If you implement them, inspect both the ledger state and the fake provider’s call count; a tidy balance can hide duplicate external work.&lt;/p&gt;

&lt;p&gt;I find this more useful than debating whether the agent is clever enough to respect a budget. The model can propose an action, but the system decides whether that action is authorized.&lt;/p&gt;

&lt;p&gt;Before your next design practice session, take one tool the agent can call and follow a single dollar through reservation, dispatch, uncertainty, and settlement. If you can explain where that dollar lives at every step, your diagram is doing something much more valuable than looking complete.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>ai</category>
      <category>webdev</category>
      <category>python</category>
    </item>
    <item>
      <title>Your Side Project Needs a Second User Before It Needs Another Feature</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Sun, 29 Nov 2026 05:13:53 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/your-side-project-needs-a-second-user-before-it-needs-another-feature-1idb</link>
      <guid>https://dev.to/emilywoodsnyc/your-side-project-needs-a-second-user-before-it-needs-another-feature-1idb</guid>
      <description>&lt;h3&gt;
  
  
  Before adding another dashboard, try opening your private data from someone else’s account.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbe66unfeh6nllohdvs55.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbe66unfeh6nllohdvs55.png" alt="Two account windows ask whether an app works for its owner and correctly denies another user." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your side project looks lovely when you are the only person using it. You created the account, uploaded the files, wrote the notes and remembered exactly which buttons to press during the demo.&lt;/p&gt;

&lt;p&gt;Now create a second account and open a link from the first one.&lt;/p&gt;

&lt;p&gt;That tiny change can turn a very convincing project into a very uncomfortable afternoon. Honestly, it is an afternoon worth having before the project reaches your resume.&lt;/p&gt;

&lt;p&gt;I like this test because it asks something a polished homepage cannot answer. Does your app understand who owns the work inside it, or does it just understand that somebody has logged in?&lt;/p&gt;

&lt;p&gt;You can try it with a job tracker, an AI study tool, a document app or that little dashboard you keep promising to finish. Pick one private object, two accounts and a clear rule about who should be allowed to use it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyi7r3o22lofkebwodcn8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyi7r3o22lofkebwodcn8.png" alt="Two account windows show that a private document should be available to its owner but not another user." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Give your project someone it cannot automatically trust
&lt;/h2&gt;

&lt;p&gt;Let’s use a tiny interview-notes app. Maya creates a note about an upcoming interview. Zoe signs up separately. Both accounts belong to you for this exercise, and you are testing your own local or development app with made-up data.&lt;/p&gt;

&lt;p&gt;Maya can open her note at &lt;code&gt;/notes/42&lt;/code&gt;. Copy that address into Zoe’s session.&lt;/p&gt;

&lt;p&gt;Use separate browser profiles, or one regular and one private window. Two ordinary tabs usually share the same login cookies, which can quietly turn your two-person experiment back into a one-person demo. Check the signed-in identity in each window before continuing.&lt;/p&gt;

&lt;p&gt;Zoe should not see Maya’s private note. She should not see its title in search, download its attachment or change its contents either.&lt;/p&gt;

&lt;p&gt;Before touching the code, write the expected result down. For this little app, Maya owns the note and can read, edit and delete it. Zoe has no access unless Maya explicitly shares it.&lt;/p&gt;

&lt;p&gt;Already, you have a more useful task than adding another settings page. You have a rule that can be wrong, and a way to find out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decide what sharing means before adding the Share button
&lt;/h2&gt;

&lt;p&gt;Suppose Maya invites Zoe as a viewer. Now reading should work, while editing and deleting should still fail. If Maya removes the invitation, Zoe’s next request for that note should be denied.&lt;/p&gt;

&lt;p&gt;Write those states in a small table. Keep it beside the code so you are checking the product you intended to build, rather than explaining whatever the current implementation happens to do.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq1v317hu7rnokdgjka12.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq1v317hu7rnokdgjka12.png" alt="Permission table for an owner, stranger, viewer and revoked viewer, with separate read, edit and delete outcomes." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a bigger version of the same reasoning, try the ownership and revocation parts of this &lt;a href="https://prachub.com/interview-questions/design-a-pc-game-store-entitlements-and-large-file-launcher-distribution?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;OpenAI-tagged game-store design exercise&lt;/a&gt;. Start by writing when someone may download or launch a purchased game, then decide what changes after access is revoked. It is a reported interview exercise, not an official OpenAI question bank, and you can leave the massive download architecture for another day.&lt;/p&gt;

&lt;p&gt;Notice how quickly a simple permission becomes a product decision. Your app has to know what being a viewer means, when that status changes and which actions depend on it.&lt;/p&gt;

&lt;p&gt;That is much more interesting to discuss than the number of libraries in your README.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hiding a button does not protect the note
&lt;/h2&gt;

&lt;p&gt;Maybe Zoe cannot see the Edit button. Lovely, the interface is communicating the right thing. But the request behind that button still needs its own permission check.&lt;/p&gt;

&lt;p&gt;On your development app, test the underlying read and update operations using Zoe’s authenticated session and Maya’s note ID. Do not substitute Maya’s login credentials along with the ID, because that would test a different situation entirely.&lt;/p&gt;

&lt;p&gt;Check both the response and the stored note. An error message is not much comfort if the update happened anyway.&lt;/p&gt;

&lt;p&gt;OWASP’s &lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html" rel="noopener noreferrer"&gt;authorization guidance&lt;/a&gt; recommends denying access by default and validating permissions on every request. In our example, the server needs to decide whether this signed-in user may perform this action on this particular note.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fegra1qpv66nhiqb8fbqh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fegra1qpv66nhiqb8fbqh.png" alt="A hidden edit button is contrasted with a server permission check that either allows an operation or denies it without changing data." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For an owner-only note, the lookup can be scoped to the authenticated owner. Once sharing exists, the rule also needs the relevant membership and permission. A client-supplied owner ID is not proof of ownership.&lt;/p&gt;

&lt;p&gt;Replacing &lt;code&gt;42&lt;/code&gt; with a long random ID does not settle the issue. Someone might receive or retain the link, and the permission must still hold. OWASP explains that distinction in its &lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Insecure_Direct_Object_Reference_Prevention_Cheat_Sheet.html" rel="noopener noreferrer"&gt;object-reference guidance&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You do not need a new permissions platform to learn from this exercise. Start with the smallest rule your app actually needs, and make every protected route obey it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep Zoe’s tab open when you remove access
&lt;/h2&gt;

&lt;p&gt;This is my favorite part of the exercise because the neat little table suddenly has to survive time passing.&lt;/p&gt;

&lt;p&gt;Let Zoe open the shared note. Then remove her access from Maya’s account without closing Zoe’s tab. Ask Zoe’s session to fetch the note again and attempt an edit.&lt;/p&gt;

&lt;p&gt;In our proposed policy, both new requests must fail. The old page being open does not grant future permission.&lt;/p&gt;

&lt;p&gt;There is a practical limit, though. Your app cannot make Zoe forget text she already saw or retrieve a file she already downloaded. Updating the screen and preventing new access are different promises, so describe them separately.&lt;/p&gt;

&lt;p&gt;If your project issues download links, write down how long an already-issued link remains valid. If immediate revocation matters, the delivery path has to enforce that requirement. Do not promise instant revocation while handing out access that lasts independently for an hour.&lt;/p&gt;

&lt;p&gt;Finally, sign out of Maya’s account and sign in as Zoe in that same browser profile. Look for Maya’s old note in the interface while fresh data loads. Server authorization and cleaning up account-specific screen state are separate jobs, and both deserve attention.&lt;/p&gt;

&lt;p&gt;You have now tested a transition, which is where a tidy demo often stops being tidy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Save the evidence, not just the fix
&lt;/h2&gt;

&lt;p&gt;Once you find a gap, give it a regression test with a boringly specific name. Something like &lt;code&gt;viewer_cannot_edit_private_note&lt;/code&gt; tells future you what broke without requiring a detective board.&lt;/p&gt;

&lt;p&gt;Keep a positive test beside the negative one. Maya should still be able to edit her own note after Zoe is blocked. An app that denies everybody can look impressively secure while being completely unusable, which is a rather expensive way to implement privacy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9acswe12mhsj0uahacd8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9acswe12mhsj0uahacd8.png" alt="A private-note leak becomes a server ownership check and two regression tests showing that the owner can read while the other account is denied." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your next practice session can stay small enough to finish.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create two isolated sessions and one private note with fictional content.&lt;/li&gt;
&lt;li&gt;Write the expected read, edit and delete permissions before running the checks.&lt;/li&gt;
&lt;li&gt;Try those operations from both identities, then repeat after sharing and revoking access.&lt;/li&gt;
&lt;li&gt;Fix one mismatch and keep tests showing both the intended success and the intended denial.&lt;/li&gt;
&lt;li&gt;Add a short README example explaining the rule, the failing case and the evidence that the change works.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Treat this as a focused engineering exercise, not a certificate that the whole app is secure. Its value is that you can explain one real boundary clearly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give yourself a better project story
&lt;/h2&gt;

&lt;p&gt;Imagine discussing this project in an interview. Instead of listing your stack, you can explain how a private note stays private, what a viewer can do and what happens when that permission disappears.&lt;/p&gt;

&lt;p&gt;If you found and fixed a bug, describe the actual bug. If everything passed, describe the checks you added. Either version is stronger than inventing a dramatic failure for the story.&lt;/p&gt;

&lt;p&gt;I prefer a small project with an honest boundary over an ambitious demo whose rules nobody has challenged yet. There is room for the prettier dashboard later.&lt;/p&gt;

&lt;p&gt;For your next session, invite that second account in and see what it can reach. You might discover that the most useful feature your project needed was a well-tested refusal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Google Interview Question: Your Calculator Works Until the Functions Start Nesting</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Sun, 29 Nov 2026 05:12:51 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/google-interview-question-your-calculator-works-until-the-functions-start-nesting-2dkk</link>
      <guid>https://dev.to/emilywoodsnyc/google-interview-question-your-calculator-works-until-the-functions-start-nesting-2dkk</guid>
      <description>&lt;h3&gt;
  
  
  One moving cursor turns a messy string into a problem you can actually explain.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbn61ncsw6spegwljs0zz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbn61ncsw6spegwljs0zz.png" alt="Google interview calculator exercise illustrated as nested add, mul and pow calls." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give me &lt;code&gt;add(2,3)&lt;/code&gt; and I can practically hear the temptation to split the string and move on. Find the comma, grab two numbers, return five, and enjoy a very brief feeling of competence.&lt;/p&gt;

&lt;p&gt;Then somebody hands over &lt;code&gt;add(5,mul(2,pow(5,2)))&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now there are three commas, several closing brackets and a function sitting where a number was supposed to be. The arithmetic is still friendly. Deciding which pieces belong together is where the interview starts getting interesting.&lt;/p&gt;

&lt;p&gt;I like this question because you do not need a compiler course to solve it. You need one precise promise about what a helper function consumes and where it stops.&lt;/p&gt;

&lt;p&gt;Let’s build that promise before writing the code, because it is the part worth remembering when the function names change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the outer function exactly two arguments
&lt;/h2&gt;

&lt;p&gt;Our calculator accepts five names, &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;sub&lt;/code&gt;, &lt;code&gt;mul&lt;/code&gt;, &lt;code&gt;div&lt;/code&gt; and &lt;code&gt;pow&lt;/code&gt;. Every call takes exactly two arguments. An argument can be an integer, including a negative one, or another complete call. Spaces may appear between tokens.&lt;/p&gt;

&lt;p&gt;For the outer &lt;code&gt;add&lt;/code&gt;, the arguments are &lt;code&gt;5&lt;/code&gt; and the whole expression &lt;code&gt;mul(2,pow(5,2))&lt;/code&gt;. Its inner commas belong to inner calls.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff1tvwgm978v0uoe53vkf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff1tvwgm978v0uoe53vkf.png" alt="The outer add call has two arguments, 5 and the complete nested mul expression; inner commas stay inside that second argument." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is why a plain comma split falls apart. It sees punctuation without understanding which level owns it. You could track bracket depth while finding the outer separator, but repeatedly slicing and rescanning nested substrings can do unnecessary work.&lt;/p&gt;

&lt;p&gt;Instead, let one cursor travel forward through the original string. A helper will consume one expression and return its value. Whoever called the helper handles the punctuation that comes next.&lt;/p&gt;

&lt;p&gt;Before continuing, try drawing those two outer arguments yourself using the &lt;a href="https://prachub.com/interview-questions/evaluate-nested-binary-arithmetic-function-calls?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;Google-tagged nested arithmetic question&lt;/a&gt;. Then mark where the cursor should land after evaluating the left argument. The listing is a reported interview exercise, not an official Google question bank.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the helper’s promise almost boring
&lt;/h2&gt;

&lt;p&gt;Call the helper &lt;code&gt;parse()&lt;/code&gt;. Starting at the current cursor, it skips whitespace, reads one complete expression, returns the result and leaves the cursor immediately after that expression.&lt;/p&gt;

&lt;p&gt;It does not swallow the caller’s comma just to be helpful. Honestly, a helpful parser that eats somebody else’s punctuation is how this gets confusing.&lt;/p&gt;

&lt;p&gt;If the next token is an integer, consume its optional minus sign and digits. If it is a function name, consume the opening bracket, parse the left expression, consume the comma, parse the right expression and consume the closing bracket. Then apply the function to those two values in that order.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxeg9vhwr5vk11p81oiim.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxeg9vhwr5vk11p81oiim.png" alt="Before parsing mul(2,3),4), the cursor points to mul; afterward it points to the following comma and the returned value is 6." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that the same helper handles both arguments. You never need a separate special case for a function inside a function inside another function. That is the lovely little payoff of describing the input recursively.&lt;/p&gt;

&lt;h2&gt;
  
  
  Walk one example all the way back up
&lt;/h2&gt;

&lt;p&gt;In &lt;code&gt;add(5,mul(2,pow(5,2)))&lt;/code&gt;, the innermost &lt;code&gt;pow&lt;/code&gt; returns 25. The waiting &lt;code&gt;mul&lt;/code&gt; now has 2 and 25, so it returns 50. Finally, &lt;code&gt;add&lt;/code&gt; has 5 and 50, which gives us 55.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2r2ouh122frivofbjl6f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2r2ouh122frivofbjl6f.png" alt="Expression tree shows pow returning 25, mul returning 50 and the outer add returning 55." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every pending call needs only its function name and the argument values it has already received. We do not have to build a separate tree in memory to evaluate this input. The picture explains the structure; the call stack remembers it while the cursor moves forward.&lt;/p&gt;

&lt;p&gt;Operand order still matters. Swapping the arguments in addition might hide a mistake, while &lt;code&gt;sub(10,3)&lt;/code&gt; immediately exposes it. Keep left and right visibly separate in the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Agree on arithmetic before Python agrees for you
&lt;/h2&gt;

&lt;p&gt;The source question leaves some arithmetic rules unspecified, so these are our practice choices. Division truncates toward zero, negative exponents are rejected, and &lt;code&gt;pow(0,0)&lt;/code&gt; returns 1. Integers have Python’s arbitrary precision, subject to available resources. Decimal literals are outside this version.&lt;/p&gt;

&lt;p&gt;That makes &lt;code&gt;div(-7,2)&lt;/code&gt; equal to -3. Python’s &lt;code&gt;//&lt;/code&gt; rounds down instead, producing -4 for &lt;code&gt;-7 // 2&lt;/code&gt;, as its &lt;a href="https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations" rel="noopener noreferrer"&gt;arithmetic documentation&lt;/a&gt; explains. Divide the absolute values using integers, then restore the sign. Going through &lt;code&gt;int(a / b)&lt;/code&gt; introduces floating-point conversion that we do not need.&lt;/p&gt;

&lt;p&gt;We will also reject invalid syntax, unknown names, division by zero and trailing input. A successful parse of &lt;code&gt;add(1,2)&lt;/code&gt; should not quietly bless &lt;code&gt;add(1,2)junk&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Write the parser around that promise
&lt;/h2&gt;

&lt;p&gt;This implementation uses one shared cursor and a small nesting limit for the exercise. It evaluates only the five operations we named; it does not execute the string as Python code.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def evaluate(text):
    i = 0
    def skip_spaces():
        nonlocal i
        while i &amp;lt; len(text) and text[i].isspace():
            i += 1
    def consume(symbol):
        nonlocal i
        skip_spaces()
        if i == len(text) or text[i] != symbol:
            raise ValueError(f'Expected {symbol} at {i}')
        i += 1
    def apply(name, a, b):
        if name == 'add':
            return a + b
        if name == 'sub':
            return a - b
        if name == 'mul':
            return a * b
        if name == 'div':
            if b == 0:
                raise ZeroDivisionError('Division by zero')
            q = abs(a) // abs(b)
            return -q if (a &amp;lt; 0) != (b &amp;lt; 0) else q
        if b &amp;lt; 0:
            raise ValueError('Negative exponent')
        return a ** b
    def parse(depth=0):
        nonlocal i
        if depth &amp;gt; 100:
            raise ValueError('Nesting limit exceeded')
        skip_spaces()
        if i == len(text):
            raise ValueError('Missing expression')
        start = i
        if text[i] == '-' or '0' &amp;lt;= text[i] &amp;lt;= '9':
            if text[i] == '-':
                i += 1
            digits = i
            while i &amp;lt; len(text) and '0' &amp;lt;= text[i] &amp;lt;= '9':
                i += 1
            if i == digits:
                raise ValueError('Missing digits')
            return int(text[start:i])
        while i &amp;lt; len(text) and 'a' &amp;lt;= text[i] &amp;lt;= 'z':
            i += 1
        name = text[start:i]
        if name not in {'add', 'sub', 'mul', 'div', 'pow'}:
            raise ValueError('Unknown function')
        consume('(')
        left = parse(depth + 1)
        consume(',')
        right = parse(depth + 1)
        consume(')')
        return apply(name, left, right)
    result = parse()
    skip_spaces()
    if i != len(text):
        raise ValueError('Unexpected trailing input')
    return result&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Read the last four lines carefully. Parsing one expression and consuming the entire input are different checks. That final check is what catches the extra &lt;code&gt;junk&lt;/code&gt; after an otherwise valid call.&lt;/p&gt;

&lt;p&gt;The depth guard is a deliberate practice limit, not a complete resource policy. Even a shallow expression can request an enormous exponentiation. A public calculator would also need limits on input length, numeric size and computation, and very deep supported inputs would need an explicit stack instead of relying on Python recursion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pick tests that cannot accidentally flatter your code
&lt;/h2&gt;

&lt;p&gt;A few successful additions will make an impressive-looking green test report without checking the awkward decisions. Choose cases that expose the exact rule you could have misunderstood.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2kjla3kv35al4u2a1u1i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2kjla3kv35al4u2a1u1i.png" alt="Test table covers operand order, truncating negative division, trailing tokens, extra arguments and negative exponents." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add a whitespace-heavy expression and a plain negative integer too. This grammar allows &lt;code&gt;-12&lt;/code&gt;, but it does not treat &lt;code&gt;- 12&lt;/code&gt; as one integer token. Spaces between tokens and spaces inside a token are different promises.&lt;/p&gt;

&lt;p&gt;I checked the implementation against fixed examples, invalid inputs, its nesting guard and 500 generated expression trees with independently calculated expected values. Those checks cover the stated exercise; they are not a claim that arbitrary hostile input is safe to evaluate without resource limits.&lt;/p&gt;

&lt;p&gt;For your own practice, predict each expected result before running anything. If an explanation takes longer than the code, that is a useful place to spend the next ten minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Explain the cost without hiding the big numbers
&lt;/h2&gt;

&lt;p&gt;Let &lt;code&gt;n&lt;/code&gt; be the number of characters and &lt;code&gt;d&lt;/code&gt; the nesting depth. The cursor-based syntax scan is O(n), and recursive frames take O(d) space. Each character is examined only a bounded number of times; we are not searching the same nested substring again and again.&lt;/p&gt;

&lt;p&gt;That is the parsing cost, though. Integer conversion and arithmetic also cost time, and arbitrary-precision intermediate values occupy memory. &lt;code&gt;pow(2,1000000)&lt;/code&gt; makes it pretty obvious why evaluating the whole expression is not automatically O(n) under a realistic arithmetic model.&lt;/p&gt;

&lt;p&gt;In an interview, state the simplified fixed-size-number analysis if requested, then name the assumption. That small distinction makes your complexity answer much easier to defend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Take the promise into the next problem
&lt;/h2&gt;

&lt;p&gt;Try adding one operation after this version works. If the grammar stays the same, most of the parser should stay the same too. If you allow a variable number of arguments, explain which part of the grammar changes before reaching for another conditional.&lt;/p&gt;

&lt;p&gt;The useful thing to keep from this exercise is not a memorized calculator. It is a helper that consumes exactly what it promised and leaves the rest for its caller.&lt;/p&gt;

&lt;p&gt;When a string looks intimidating, find the smallest complete piece inside it. Sometimes the clean solution begins with being very particular about who gets to eat the next comma.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>webdev</category>
      <category>google</category>
    </item>
    <item>
      <title>You Don’t Need Good News to Call Your Friends</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Mon, 23 Nov 2026 20:44:50 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/you-dont-need-good-news-to-call-your-friends-4p68</link>
      <guid>https://dev.to/emilywoodsnyc/you-dont-need-good-news-to-call-your-friends-4p68</guid>
      <description>&lt;h3&gt;
  
  
  For anyone postponing a catch-up until there’s something impressive to report.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9cvqdzqlu5g1oonsacmc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9cvqdzqlu5g1oonsacmc.png" alt="Two friends share a kitchen table and a warm drink, with a phone and envelope set aside." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your friend asks when you’re free, and you start checking whether your life is impressive enough for coffee.&lt;/p&gt;

&lt;p&gt;You could go on Saturday. You even want to. But somewhere between reading the message and replying, you imagine the question about work, and now you’re negotiating with yourself.&lt;/p&gt;

&lt;p&gt;Maybe after the next interview. Maybe when the offer comes through. Then you can explain the quiet weeks with a nice ending, and nobody has to watch you still figuring it out.&lt;/p&gt;

&lt;p&gt;Meanwhile, your friend has only asked whether you want to get pancakes.&lt;/p&gt;

&lt;p&gt;I want to make a small case for going before you have the ending.&lt;/p&gt;

&lt;h2&gt;
  
  
  A catch up can start to feel like a progress report
&lt;/h2&gt;

&lt;p&gt;Job hunting gives you so many versions of the same question. What have you done? What are you working toward? Why should someone pick you?&lt;/p&gt;

&lt;p&gt;After a while, it’s possible to carry that whole presentation into a conversation where nobody requested it.&lt;/p&gt;

&lt;p&gt;You rehearse the acceptable version of your week. You leave out the afternoon that disappeared into applications. You mention a course because at least that sounds productive. Even a friendly question can feel awkward when your honest answer is that you’re still waiting.&lt;/p&gt;

&lt;p&gt;And honestly, sometimes people do make it awkward. They offer advice before you finish, compare your timeline with someone else’s, or ask about the search every single time you speak. You don’t have to make those people your first call.&lt;/p&gt;

&lt;p&gt;But think about the friend who sends you a picture of a badly parked car because you both have unreasonable opinions about parking. The person who still wants your verdict on their haircut. Have they actually asked you to come back successful, or have you added that requirement yourself?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5duat1aq7r99q9xsqq6s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5duat1aq7r99q9xsqq6s.png" alt="A woman postpones a call while thinking about a job offer, then reconnects through an ordinary conversation about the day." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  You can explain the silence without defending your life
&lt;/h2&gt;

&lt;p&gt;There’s an annoying little complication here. Once you’ve postponed a reply for long enough, you can start believing you need an even better reason to return.&lt;/p&gt;

&lt;p&gt;Now the message needs good news, an apology and a convincing explanation for why it took three weeks. So you leave it another day, which is a very effective way to make tomorrow’s message feel even bigger.&lt;/p&gt;

&lt;p&gt;I like a reply that lets the other person know what’s happening without handing them your entire application history.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I’ve been quieter because the job search has been getting to me. Nothing new to announce, but I miss you. Are you free for a walk this weekend?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you want company without a conversation about work, you can say that too.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I’d love to see you, but could we skip career advice this time? I really want to hear what you’ve been up to.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Neither message needs a cheerful update attached. You’re giving your friend a way to meet you where you are, and you can keep the details you don’t want to share private.&lt;/p&gt;

&lt;p&gt;They might be busy. They might take a while to reply. Sending the message doesn’t guarantee a lovely afternoon, but it does give the friendship something to respond to besides your absence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let something ordinary happen while you’re waiting
&lt;/h2&gt;

&lt;p&gt;I’m not going to tell you that pancakes fix unemployment. Rent is real, uncertainty is exhausting, and an invitation to an expensive brunch can be its own source of stress.&lt;/p&gt;

&lt;p&gt;You can go for a walk or cook whatever is already in the kitchen. Calling while you both fold laundry is a perfectly respectable social arrangement, and neither of you has to locate a clean outfit first.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnqxyy642c1w1shmnj8vr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnqxyy642c1w1shmnj8vr.png" alt="Two friends laugh over an imperfect pancake in an ordinary kitchen, with a phone set aside." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What I want for that hour is a conversation that can wander. Maybe you talk about the search for ten minutes, then argue about a television ending. Maybe you discover that your friend has also had a weird week, although you couldn’t have guessed it from their posts.&lt;/p&gt;

&lt;p&gt;You can care deeply about getting your next job and still have something to say about dinner. You can be disappointed and occasionally funny in the same evening. None of that makes you less serious about changing your situation.&lt;/p&gt;

&lt;p&gt;When the offer arrives, of course you can make the excited phone call. I hope you have several people to call, and that someone gets embarrassingly happy on your behalf.&lt;/p&gt;

&lt;p&gt;Until then, you’re allowed to answer the pancake invitation.&lt;/p&gt;

&lt;p&gt;Your friend may already know you have no news. They may just miss having breakfast with you.&lt;/p&gt;

&lt;p&gt;If you are actively preparing for your tech interview, don’t forget to check my other blogs where I shared actual interview questions and their solutions or just follow and subscribe me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>career</category>
    </item>
    <item>
      <title>Amazon Interview Question: Count Connected Groups, Then Handle a Stream of Edges</title>
      <dc:creator>Emily Woods</dc:creator>
      <pubDate>Mon, 23 Nov 2026 20:44:40 +0000</pubDate>
      <link>https://dev.to/emilywoodsnyc/amazon-interview-question-count-connected-groups-then-handle-a-stream-of-edges-3db9</link>
      <guid>https://dev.to/emilywoodsnyc/amazon-interview-question-count-connected-groups-then-handle-a-stream-of-edges-3db9</guid>
      <description>&lt;h3&gt;
  
  
  One graph, a working Python solution, and the follow-up that changes which data structure makes sense.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9zo7802zyh09egqv8nvp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9zo7802zyh09egqv8nvp.png" alt="Amazon interview practice with six nodes divided into three connected groups." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Six nodes and five edges should leave one group if you subtract the edges from the nodes. Unfortunately, the graph has other plans.&lt;/p&gt;

&lt;p&gt;Try this before scrolling. Nodes are numbered 0 through 5, and the undirected edges are &lt;code&gt;(0,1), (1,2), (2,0), (3,4), (4,4)&lt;/code&gt;. How many connected groups remain?&lt;/p&gt;

&lt;p&gt;If your answer is three, keep going anyway. The interesting follow-up is what happens when another edge arrives and you need the new answer immediately.&lt;/p&gt;

&lt;p&gt;This is the kind of question I like practicing because the first version is friendly enough to draw on paper, but the follow-up checks whether the explanation survives a change in requirements. We’ll solve both versions, then look at the change our final solution cannot handle on its own.&lt;/p&gt;

&lt;h2&gt;
  
  
  First, count the groups you can actually draw
&lt;/h2&gt;

&lt;p&gt;Nodes 0, 1 and 2 form a triangle. Nodes 3 and 4 form another group. Node 5 is sitting there with no edges, and yes, it still gets to count.&lt;/p&gt;

&lt;p&gt;That leaves &lt;strong&gt;three connected components&lt;/strong&gt;. Inside a component, you can travel between any two nodes by following edges. You cannot travel from one component to another.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4dv0te5cd7at97yr59y0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4dv0te5cd7at97yr59y0.png" alt="A triangle containing 0, 1 and 2, a pair containing 3 and 4 with a self-loop at 4, and isolated node 5 form three groups." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The shortcut &lt;code&gt;nodes - edges&lt;/code&gt; breaks because an edge doesn’t necessarily join two separate groups. Adding &lt;code&gt;(2,0)&lt;/code&gt; closes a triangle inside an existing group. Adding &lt;code&gt;(4,4)&lt;/code&gt; points a node back to itself. Neither should reduce the count.&lt;/p&gt;

&lt;p&gt;Duplicate edges behave the same way. Seeing &lt;code&gt;(0,1)&lt;/code&gt; again doesn’t create a new connection between previously separate groups.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Count successful merges, not raw edges.&lt;/strong&gt; That distinction will do most of the work for us.&lt;/p&gt;

&lt;p&gt;My example builds on the graph portion of this &lt;a href="https://prachub.com/coding-questions/implement-cache-and-count-components?utm_source=devto&amp;amp;utm_campaign=v1012" rel="noopener noreferrer"&gt;Amazon tagged two part practice question&lt;/a&gt;. The company label is a reported practice attribution, while the walkthrough and code below are my own. We’re leaving its separate cache problem aside.&lt;/p&gt;

&lt;p&gt;Our contract is an undirected graph with nodes &lt;code&gt;0&lt;/code&gt; through &lt;code&gt;n - 1&lt;/code&gt;, valid endpoints, and possible duplicate edges and self-loops. We’ll also return zero for an empty graph. All nodes are known before processing starts.&lt;/p&gt;

&lt;h2&gt;
  
  
  For a graph you already have, traversal is enough
&lt;/h2&gt;

&lt;p&gt;Start from a node you haven’t visited and explore everything reachable from it. That entire exploration belongs to one group. Repeat until every node is visited.&lt;/p&gt;

&lt;p&gt;Notice that the outer loop must cover all &lt;code&gt;n&lt;/code&gt; nodes. Looping only over the endpoints in the edge list would quietly forget node 5, which is a rude way to lose a perfectly good component.&lt;/p&gt;

&lt;p&gt;Here’s an iterative depth-first search, so a long chain doesn’t depend on Python’s recursion limit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;count_groups_dfs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;graph&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;neighbor&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;neighbor&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;neighbor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;neighbor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Marking a node when it enters the stack prevents multiple neighbors from adding it again. Duplicate edges still take time to inspect, but they don’t change the answer.&lt;/p&gt;

&lt;p&gt;For &lt;code&gt;n&lt;/code&gt; nodes and &lt;code&gt;m&lt;/code&gt; supplied edges, this version takes &lt;code&gt;O(n + m)&lt;/code&gt; time and &lt;code&gt;O(n + m)&lt;/code&gt; additional space, including the adjacency lists. It’s a complete answer when the input is a finished graph and we need one final count.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now the edges arrive one at a time
&lt;/h2&gt;

&lt;p&gt;Suppose we need the count after every insertion. Rebuilding and traversing the graph each time repeats work we’ve already done.&lt;/p&gt;

&lt;p&gt;We can instead begin with &lt;code&gt;n&lt;/code&gt; separate groups and merge them as connections arrive. This is where &lt;strong&gt;union-find&lt;/strong&gt;, also called a disjoint-set structure, earns its place.&lt;/p&gt;

&lt;p&gt;Each group has a representative root. To process &lt;code&gt;(a,b)&lt;/code&gt;, find both roots. Different roots mean two groups are becoming one, so reduce the count by one. Matching roots mean both nodes were already connected, so leave the count alone.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fojil0med8usvspbe7le9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fojil0med8usvspbe7le9.png" alt="A trace starts at six groups and falls to five, four, four, three and three as edges arrive." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For our example, the counts after the five edges are &lt;code&gt;[5,4,4,3,3]&lt;/code&gt;. Add &lt;code&gt;(2,3)&lt;/code&gt; next and the triangle joins the pair, leaving two groups. Node 5 remains alone until an edge reaches it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flumy2xblitzv7x9e481h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flumy2xblitzv7x9e481h.png" alt="Adding edge 2 to 3 joins two components while isolated node 5 stays separate." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the implementation close to that explanation
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;parent[x]&lt;/code&gt; leads toward the representative of x’s group. A root points to itself. &lt;code&gt;size[root]&lt;/code&gt; records the group’s size, and we attach the smaller group under the larger one.&lt;/p&gt;

&lt;p&gt;While finding a root, we also point nodes toward their grandparents. This is path halving, which shortens future searches. These parent links are bookkeeping links; they do not have to be edges in the original graph.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Groups&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add_edge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;ra&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ra&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;rb&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ra&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rb&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;ra&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ra&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rb&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ra&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ra&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rb&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;ra == rb&lt;/code&gt; check handles a cycle, a duplicate edge and a self-loop without three separate patches. In each case, there is no new merge to count.&lt;/p&gt;

&lt;p&gt;For a single final answer, use the same structure through a small wrapper.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;count_groups&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;groups&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Groups&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;groups&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_edge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;groups&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a stream, create &lt;code&gt;Groups(n)&lt;/code&gt; once and call &lt;code&gt;add_edge&lt;/code&gt; as each edge arrives. Its return value is the current answer. There’s no need to keep the entire edge history just to maintain that count.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the code a test that can disagree with you
&lt;/h2&gt;

&lt;p&gt;Please don’t stop at a chain where every edge joins two different components. That example lets the incorrect subtraction shortcut look brilliant.&lt;/p&gt;

&lt;p&gt;These small checks ask more useful questions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;count_groups&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;count_groups&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;count_groups&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Groups&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;edges&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_edge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can go further by generating small random edge streams and comparing union-find’s count after each insertion with a fresh traversal of all edges seen so far. The slower implementation becomes a useful reference precisely because it reaches the answer differently.&lt;/p&gt;

&lt;p&gt;With union by size and path halving, processing all &lt;code&gt;m&lt;/code&gt; edges costs &lt;code&gt;O(n + m α(n))&lt;/code&gt; amortized time, where &lt;code&gt;α&lt;/code&gt; is the inverse Ackermann function. It grows extremely slowly, but calling every operation worst-case &lt;code&gt;O(1)&lt;/code&gt; would still be inaccurate. Princeton’s &lt;a href="https://algs4.cs.princeton.edu/15uf/WeightedQuickUnionPathHalvingUF.java.html" rel="noopener noreferrer"&gt;union find reference&lt;/a&gt; covers this distinction. The structure uses &lt;code&gt;O(n)&lt;/code&gt; extra space, excluding the input and any output list you choose to collect.&lt;/p&gt;

&lt;h2&gt;
  
  
  The follow-up that deserves a different answer
&lt;/h2&gt;

&lt;p&gt;Keeping track of the largest group is a small extension. After a successful merge, compare the new root’s size with a running maximum. Start that maximum at one when &lt;code&gt;n &amp;gt; 0&lt;/code&gt;, or zero for an empty graph.&lt;/p&gt;

&lt;p&gt;Removing an edge is a very different request.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foajva3i1t6n4pd2lo0gz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foajva3i1t6n4pd2lo0gz.png" alt="An engineer explains that union-find merges groups, while a colleague asks what happens when an edge is removed." width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ordinary union-find cannot split a component. It also doesn’t retain enough graph information to decide whether a removed edge was the only route between two regions. Removing one side of a triangle leaves it connected; removing a bridge between two groups can separate them.&lt;/p&gt;

&lt;p&gt;For occasional removals on a small graph, keeping the edges and rebuilding connectivity may be reasonable. Frequent deletions need a different plan, such as an appropriate offline rollback approach when the full update sequence is known, or a dynamic-connectivity structure. Plain path-halving union-find is not automatically a rollback implementation.&lt;/p&gt;

&lt;p&gt;This is the part of the explanation worth practicing out loud. Traversal answers one completed graph. Union-find maintains groups while edges are added. Deletions change the problem again.&lt;/p&gt;

&lt;p&gt;Before closing the tab, redraw the six node example without the code and add one edge that changes the answer, then one that doesn’t. If you can explain both before touching the keyboard, you have the reason behind the solution, not just the template.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;~ Emily&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>python</category>
    </item>
  </channel>
</rss>
