
The Frugal Architect in a Chaotic World
What happens when your Kubernetes clusters scale perfectly, dashboards stay green, and tests pass, but infrastructure costs keep rising? In The Frugal Architect in a Chaotic World, I share three lessons from a real-world customer engagement, exploring how AWS Graviton, Spot Instances, Karpenter, observability, and code profiling can uncover hidden inefficiencies. From smarter autoscaling to CPU optimization, discover why efficient computing starts by challenging assumptions, not just cutting costs.
A few months ago I was working with a customer running a large e-commerce platform on EKS. It was one of those environments where nothing immediately catches your attention. Deployments were routine, autoscaling had already been exercised during previous traffic spikes, and the engineering team had done a good job keeping the platform operational. If you opened Grafana, everything looked reasonably healthy. CPU wasn't saturated, latency stayed within the agreed objectives most of the time, and there wasn't a backlog full of production incidents waiting to be explained.
The first question didn’t come from operations, it came from finance. Their monthly infrastructure bill had been increasing for several months while business metrics remained relatively stable. Nobody was claiming the platform had suddenly become twice as busy, yet compute consumption kept moving in the wrong direction.
The initial assumption was the obvious one: maybe traffic had increased. Maybe a service had
started consuming more memory, or maybe somebody had introduced an aggressive autoscalingnt policy during the last release. None of those turned out to be true. The Kubernetes clusters were behaving exactly as configured. HPA scaled when expected, nodes were provisioned correctly, and the workloads themselves were healthy.
The more we looked at the platform, the clearer it became that this wasn't a Kubernetes problem. It was the result of years of reasonable engineering decisions that nobody had revisited.
Someone had increased CPU requests after a production incident. Another team had expanded scaling limits before Black Friday. A service had received larger instances because a dependency couldn't keep up under load. Every decision solved the problem it was meant to solve, but the workload had evolved while those decisions remained in place.
That was the first time during the engagement that somebody asked a question we probably should have asked much earlier: if we were designing this platform today, knowing what we know now about its traffic patterns, would we build it the same way?
Looking back, that question ended up being far more useful than searching for another dashboard.
Lesson one: We scaled perfectly, and the costs went through the roof
Law I: Make Cost a Non-functional Requirement
The customer had designed the platform to survive unpredictable traffic. Like many Kubernetes deployments, autoscaling was initially driven by CPU utilization because that's the default and, in many cases, it's good enough. The problem is that CPU utilization isn't always a good representation of user experience. A service can be sitting at 40% CPU while requests are backing up behind a slow dependency or waiting in a queue. From Kubernetes' perspective nothing is wrong. From the user's perspective the application feels slower.
Instead of relying exclusively on CPU, we switched to KEDA so scaling decisions could be driven by application metrics such as request latency and queue depth. That allowed the platform to react to conditions that actually reflected what users were experiencing rather than what the operating system reported.
Node provisioning was handled by Karpenter. For the initial benchmarks we deliberately limited the number of instance types to keep the comparison consistent, but that isn't how I recommend running production environments. Once we finished validating the workload, we moved to Attribute-Based Instance Selection (ABIS). Rather than maintaining a list of instance families, we described the resources we needed (processor architecture, vCPUs and memory) and let Karpenter select from the widest possible pool of matching instances. Besides simplifying the configuration, it also improves flexibility when new EC2 instance generations become available or Spot capacity changes across Availability Zones.
Before touching production we wanted to understand how the platform behaved under load. We used k6 to generate traffic, but instead of the classic linear ramp-up that appears in many examples, we introduced Monte Carlo simulations to add randomness to arrival rates. Real customers rarely behave like a benchmark script. They arrive in bursts, campaigns don't start gradually, and traffic has an annoying tendency to spike at exactly the wrong moment.
The results were exactly what the engineering team expected. The platform comfortably handled more than 10,000 concurrent users. Pods scaled when latency increased, Karpenter provisioned new nodes fast enough to absorb demand, and the application remained responsive throughout the test.
What nobody had measured was the cost of achieving that result.
Benchmarking the alternatives
Running the same workload across different infrastructure configurations gave us a much clearer picture than looking at utilization graphs alone.
Configuration | Instance Type | Pricing Model | Hourly Cost | Notes |
|---|---|---|---|---|
Baseline | m5.large (x86) | On-Demand | ~$0.096 | Default setup |
Optimized | c6g.large (Graviton) | On-Demand | ~$0.068 | ~30% cheaper |
Optimized | c6g.large (Graviton) | Spot | ~$0.020 | ~80% cheaper |
The application was exactly the same in every test. Same container images, same traffic profile, same autoscaling configuration. We weren't trying to optimize the application itself; we wanted to understand how much of the bill came from infrastructure choices rather than software design.
There's an important detail here. This wasn't completely effortless because the customer had already invested in multi-architecture container images. That meant the workloads could run on Graviton without rebuilding the application. If you're starting from x86-only images, the migration usually involves validating your dependencies, rebuilding your containers and exercising your CI pipeline on Arm. Most modern runtimes work well on Graviton, but it's still worth verifying everything before moving production workloads.
The benchmark results surprised the customer more than they surprised us.
The Graviton configuration consistently matched the baseline while reducing infrastructure costs, and in several runs it delivered slightly better P95 latency. The Spot-based configuration produced the biggest difference. Despite running on interruptible capacity, latency remained stable throughout the load test because the application had already been designed as a collection of stateless services. Losing an instance wasn't a failure scenario; Kubernetes simply scheduled replacement pods while Karpenter provisioned additional capacity when needed.
The graphs below summarizes what we observed during the ten-minute benchmark.


The interesting part isn't that Spot was cheaper. Everyone expects that. What mattered was that the workload didn't need dedicated On-Demand capacity to deliver a good user experience. The architecture already had the characteristics that make Spot viable in production. We simply hadn't taken advantage of them.
One of the misconceptions I encounter quite often is that Spot is only appropriate for batch processing or non-critical workloads. That's certainly one use case, but it's far from the only one. If your application is stateless, resilient to interruptions and capable of replacing capacity quickly, many customer-facing services can also benefit. The important part isn't whether an instance disappears. It's whether your architecture assumes that it eventually will.
Law V: Cost-Aware Architectures Implement Cost Controls
What surprised me wasn't that Graviton reduced infrastructure costs or that Spot made the bill even smaller. We've known that for years. What surprised me was how little attention the team paid to cost while making technically sound decisions. They measured latency, availability, throughput, etc. Every deployment was validated against operational metrics, yet nobody could answer a simple question: how much does serving a request actually cost?
I've seen the same pattern in many customer engagements. Cost is often treated as something finance reviews at the end of the month instead of another engineering metric that deserves continuous attention. The result is predictable. Resource requests grow after an incident, scaling limits increase before a major event, larger instance types become permanent after a temporary problem, and very few of those decisions are revisited later.
There's nothing inherently wrong with any of those changes. Most of them solved a real problem at the time. The mistake is assuming they remain the right solution as the application evolves.
For this customer, the biggest savings didn't come from rewriting the application. They came from the infrastructure that had quietly become the default. Running the workload on Graviton improved price-performance, and combining it with a well-diversified Spot strategy reduced costs even further without changing the application's behavior.
That experience reinforced something I now try to discuss early in every architecture review. Cost deserves the same attention as latency, availability and reliability. If you're only looking at it after the monthly invoice arrives, you're measuring it too late.
Lesson two: Everything looked healthy, but users disagreed
Law IV: Unobserved Systems Lead to Unknown Costs
By the time we finished the infrastructure work, the customer had a platform they were happy with. The migration to Graviton had reduced infrastructure costs, Spot capacity was handling a significant portion of the workload, and the Kubernetes clusters behaved exactly as expected under load. From an operational perspective, it felt like we were done.
A couple of weeks later the support team started receiving an unusual type of complaint. Users started complaining: "The app feels slower sometimes. Nothing dramatic, just… weird."
Those comments are always uncomfortable because they don't usually come with enough information to reproduce the problem. The first reaction was to go back to Grafana and CloudWatch. CPU looked fine. Memory looked fine. Network traffic hadn't changed. Autoscaling wasn't behaving differently from the previous weeks and backend latency was still within the agreed objectives. Nothing in the data explained what users were feeling.
At that point we could have closed the investigation saying everything was healthy. But instead of that, we started looking outside the backend.
The customer already had a good observability stack. Grafana dashboards, Prometheus metrics, CloudWatch alarms, even basic tracing with AWS X-Ray. They were all collecting useful information, but almost everything stopped at the application boundary. We knew how requests behaved once they reached our services. We didn't know what happened before or after. And that became obvious as soon as we captured a browser trace.
One script loaded synchronously from a third-party analytics provider was sitting in the <head> of every page.
<script src="https://analytics.partner-vendor.com/tracker.js"></script>
A single script tag added between 200 and 400 milliseconds to page rendering. Nothing failed, no errors were logged, and none of the backend metrics suggested there was a problem. Those few hundred milliseconds were enough for users to perceive the application as slower, even though every request completed successfully. The latency existed entirely in the browser, outside the visibility of the backend dashboards.
The tricky part was that it didn’t happen on every request. If DNS resolution was slow or the provider had higher latency in a particular region, the browser simply waited for the download to finish before rendering the page. From the backend's perspective, the request had already completed successfully. The response had been generated and sent; the browser was simply waiting for the external script before it could render the page.
That also explained why only some users complained. Most requests completed normally, so aggregate latency barely changed. Depending on where users connected from, between five and fifteen percent of page loads spent an extra few hundred milliseconds waiting for a JavaScript file that nobody even remembered adding.
We removed the script and the complaints stopped.
The fix itself wasn’t very interesting, but finding it was. That script had been part of the application for months, quietly affecting a percentage of users without triggering a single alert. We had plenty of backend metrics, but none of them could tell us what happened after the response left the application.
What changed afterwards
Finding the script solved the immediate incident, but it also exposed something more valuable: a blind spot in the observability strategy. Until then, the visibility ended at the backend. Customer could explain every millisecond spent inside their APIs, containers, and databases, yet they had almost no understanding of what happened inside the user's browser before the page became usable.
From an observability perspective, that was a (huge) gap.
After that incident, we extended their telemetry beyond the backend. We introduced Real User Monitoring (RUM) to correlate what their services reported with what users actually experienced. Instead of starting at the load balancer, distributed traces now followed the entire journey… from the browser, through the frontend, across the network, and into the application itself.
That single change transformed how customer investigated performance problems. They stopped optimizing what servers believed was happening and started optimizing what users were actually seeing.
The incident also changed the way they evaluated third-party dependencies. Before, a new JavaScript library was often viewed as "just another script" added for analytics, marketing, or customer insights. Afterward, every external dependency became part of the architecture discussion. If it executed on the critical rendering path, it deserved the same scrutiny as any backend component. Convenience was no longer a good enough reason.
Finally, we added a small but surprisingly effective guardrail to their CI pipeline. Every pull request is now checked for synchronous external scripts. The check itself is simple, but it forces to ask a question that nobody asked the first time: Does this resource really need to block the page from rendering?
Before this engagement I used to think about observability mainly in terms of operating distributed systems. This customer reminded me that observability has another purpose: preventing waste. The browser was waiting, users were retrying requests, Kubernetes was scaling correctly, and infrastructure costs were increasing for reasons that had nothing to do with compute. None of that was visible until we expanded what we were measuring.
Lesson three: Working code isn’t always efficient code
Law VI: Cost Optimization is Incremental
The analytics script incident reinforced something I often see with customers: invisible things cost real money.
By this point we had already challenged a few assumptions about their platform. Autoscaling wasn't solving every efficiency problem, and healthy dashboards didn't necessarily mean users were getting a good experience. So, we moved one layer deeper.
We started looking at the rest of their stack, focusing on the parts everyone considered "done." The code had been in production for years, the tests passed, and nothing suggested it needed attention. It just worked, so nobody questioned whether it could work more efficiently.
We weren't looking for the most computationally expensive function in the application. We were looking for one that executed constantly and sat directly in the customer journey. Shopping cart validation was a good candidate. Every purchase passes through it, so even a modest improvement could reduce CPU consumption at scale while making the checkout experience slightly more responsive.
The implementation was straightforward:
def check_cart(cart): total = 0 for item in cart: if item['quantity'] > 0: total += item['price'] * item['quantity'] return totalThe function wasn't broken. Every unit test passed. Integration tests did too. We had thrown plenty of traffic at it, and it behaved exactly as expected. Nobody had complained, no alerts had fired, and there wasn't a bug waiting to be fixed.
So why touch it at all? Because correctness is only half the story.
The question wasn't whether the code worked. The question (which we don't ask often enough) was whether it was spending more CPU cycles than it needed to.
Instead of trying to outsmart the compiler or manually rewriting the function, we gave Amazon Kiro a simple challenge: Can you implement the same logic differently?
It came back with this:
def check_cart(cart): return sum(item['price'] * item['quantity'] for item in cart if item['quantity'] > 0)At first glance, nothing looks particularly exciting. Just a slightly different way of expressing the same idea. So we did what performance engineers are supposed to do…we measured it. Both implementations ran under the same conditions on AWS Graviton (multiple runs, ten thousand requests, side by side). The improvement was small but consistent: a 2%-3% speedup. That’s it.
If this function runs a few hundred times a day, you won't notice the difference.
If it sits on the critical path of an e-commerce platform processing millions of requests, those percentages stop looking so small. A few CPU cycles disappear from every request, and eventually that translates into less compute, lower infrastructure costs, and a little less energy consumed. That's the part people often miss about performance engineering.
Nobody wakes up one morning, finds a single optimization, and suddenly cuts their infrastructure bill in half. Real improvements usually come from dozens (or hundreds) of small changes like this. Most aren't exciting on their own. Together, they can completely change the efficiency profile of an application.
That's why I don't think of Amazon Kiro as an optimization tool. I think of it as another engineer sitting next to me, proposing ideas I might not have considered. Sometimes the generated code performs better… and sometimes it doesn't. Either way, it gives you another implementation to evaluate instead of relying on intuition.
The important part comes next. Benchmark it.
If the difference is measurable, great. If it isn't, you've still learned something about your application. That's also why profiling comes before optimization. Tools like aperf, perf, and Flamegraphs show where the CPU is actually spending its time. There's little value in shaving a few cycles off a function that barely runs, while the real bottleneck sits somewhere else.
In practice, performance improvements rarely come from a single breakthrough. They come from lots of small decisions: removing an unnecessary allocation, avoiding an extra copy, simplifying a hot path, or replacing an implementation with one that does the same work more efficiently.
None of those changes are particularly exciting on their own. Together, they can make a big difference.
The incremental mindset
Law VII: Unchallenged Success Leads to Assumptions
The whole exercise took less than ten minutes, and it revealed how many assumptions we'd quietly accumulated over time. The function passed every test, so we assumed it was good enough. Nobody had complained about latency, so we assumed performance wasn't an issue. The infrastructure had been running for months, so we assumed the architecture was still the right one. None of those assumptions were malicious… they were simply never challenged.
Functional correctness is usually where a feature reaches the finish line. Once the tests are green, attention naturally shifts to the next backlog item. Performance rarely receives the same scrutiny unless customers start noticing it.
That's where tools like Amazon Kiro become interesting. Not because they automatically produce better code, but because they encourage you to question implementations that everyone has already accepted. Every alternative is just another hypothesis.
The benchmark decides whether it's worth keeping.
Designing for chaos, not against it
These three lessons came from the same customer engagement.
As you can see, nothing was obviously wrong. The architecture scaled, dashboards were green, tests passed. If you had looked at the operational metrics alone, you would probably have called the system healthy. And yet, there was waste almost everywhere.
Instances that were larger than they needed to be... dependencies doing work nobody realised was happening, code that had been correct for years, but had never been profiled because there was never a reason to question it.
The Frugal architecture isn't about choosing the cheapest service or chasing the lowest AWS bill. It's about understanding where your compute budget is actually going and deciding whether every CPU cycle, every dependency, and every request is delivering value. It's no different from managing latency budgets or defining SLAs. You measure them because they matter. Cost deserves the same discipline.
In a chaotic world, the goal isn't to eliminate surprises. It's to find them before they appear in your customer's experience, your cloud bill, or your sustainability report.
Measure > Challenge assumptions > Measure again.
That's what frugal architecture really is, an engineering discipline built on curiosity, evidence, and continuous improvement.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article