Limited availability · Q4 slots filling now
Adriano Junior
HomeServicesCasesAboutArticlesAppsLet's talk
API refactor & rebuild

P95latency,cut.

Performance-first API refactor or rebuild with measurable latency wins. I took Cuez from 3 seconds to 300ms — 10x faster, 40% less infrastructure cost. Same method, applied to your API.

See Custom Web Apps→
Problem solvedAPI Rebuild and Refactor$4,999/mo
  1. Scope
  2. Ship
  3. Iterate

monthly subscription

Who this is for

You're a CTO or technical co-founder sitting on a 5+ year old monolith API. P95 response times are climbing, feature velocity is falling, and the team is stuck arguing refactor vs rebuild without a clear framework to decide. This service is for exactly that situation.

The pain today

  • P95 latency climbing with no clear root cause
  • Every new feature seems to slow the API further
  • Monitoring shows slow queries but no clear fix priority
  • Infrastructure cost growing faster than traffic
  • Team deadlocked between incremental refactor and a full rebuild

The outcome you get

  • Baseline measurement — P95, P99, throughput, and cost per transaction
  • Prioritized refactor plan with expected latency and cost wins per phase
  • Incremental extraction patterns that avoid big-bang rewrites
  • Measurable wins shipped within the first month
  • Architecture decisions documented so your team owns the knowledge, not a dependency

Refactor vs rebuild: a seven-factor decision

Most teams frame this as a philosophical debate. I treat it as a scoring exercise.

Factor one: codebase age. Over 7 years usually tips toward rebuild; under 5, refactor is almost always faster and cheaper. Factor two: test coverage. Low coverage makes refactor genuinely dangerous — every change is a guess. Factor three: architectural clarity. If domain boundaries are muddled, a refactor just polishes mud; a rebuild lets you draw clean lines. Factor four: team tenure. A team that has rotated heavily can't safely refactor what they didn't write. Factor five: business velocity pressure. High shipping pressure means incremental wins or nothing — you can't freeze the product for six months. Factor six: technology freshness. PHP 5.6 is rebuild territory; PHP 8.2 is not. Factor seven: cost of failure. Payment and medical APIs favor slow, careful refactor over any rebuild risk.

Once these are on paper, the answer is usually obvious. The debate isn't really about refactor vs rebuild — it's about teams being afraid to name the real constraint.

Baseline measurement — P95, P99, throughput, and cost per transaction

Measure before you touch code

Optimization without measurement is theater. Before I write a line, I need a baseline: P50, P95, and P99 latency per endpoint; throughput in requests per second at each latency tier; infrastructure cost per transaction; and error rate under normal load.

Tools: APM (Datadog, New Relic, or Honeycomb), the database slow query log, and cloud billing detail broken down by service. One week of baseline data is enough to identify the 3 to 5 endpoints that dominate latency and cost. It's almost always 80/20 — a handful of endpoints doing most of the damage.

I resist the instinct to clean up code until the data says that specific code is responsible for a measured cost. Opinions about messy code are free. APM bills are not.

3s → 300ms: API response time.
Cuez by Tinkerlist

Database and query optimization: where most latency lives

In my experience across Cuez, bolttech, and Imohub, slow database queries are behind 60 to 70% of P95 problems. The API code is often fine. The queries are not.

Common culprits: N+1 query patterns hiding behind clean-looking ORM code, missing indexes on columns used in WHERE clauses, queries that return far more columns than the response actually uses, and connection pool exhaustion under load. Each of these can add hundreds of milliseconds without any obvious log entry.

The fix sequence: slow query log first, then EXPLAIN plans on the worst offenders, then index additions or query rewrites, then caching only where caching is genuinely warranted. Caching a broken query hides the problem — it doesn't fix it. I've seen teams cache their way into a much harder problem when the underlying data model was the actual issue.

Incremental extraction patterns

A big-bang rewrite has a poor track record. The incremental approach takes longer on paper but delivers working code at every stage.

Strangler fig: stand up the new service alongside the old monolith, route specific endpoints to the new service, and retire old endpoints one by one. Read path extraction: serve reads from the new service while writes still go to the monolith, which keeps the critical write path stable during transition. Shadow traffic: send production requests to both old and new implementations, compare responses, and catch regressions before any cutover. Feature-flag rollout: gate the new service behind a flag and ramp from 1% to 10% to 50% to 100% with APM open at each stage.

I used these patterns across the Cuez API work and at bolttech, where the payment service processed 40+ provider integrations without a cutover incident. The patterns are not exotic — they are standard practice. The discipline to follow them when there's pressure to ship faster is what separates a clean migration from an outage.

Case study: Cuez API (3s to 300ms)

Cuez builds SaaS for live broadcast production. Their core API averaged 3 seconds per response, which was blocking user growth — the product felt broken even when the features worked.

I took it to 300ms. That's 10x faster. The work: query optimization on 3 specific endpoints that accounted for most of the latency, strategic Redis caching placed at the right layer rather than applied everywhere, moving async-safe work out of the request path, and targeted database schema adjustments. Secondary result: roughly 40% infrastructure cost reduction, because the API now handles far higher throughput on the same hardware.

The techniques are not novel. The value is in doing the measurement first, knowing which 3 endpoints to fix, and resisting the urge to cache or rewrite things that aren't causing the problem. Discipline over cleverness.

Pricing and what you keep

API refactor and rebuild work fits the Applications service. Standard tier is $4,999/mo and covers typical monolith API work — query optimization, caching strategy, incremental extraction. Pro tier is $5,499/mo for multi-service architectures or performance-critical systems like payment processing or real-time data pipelines.

First phase — measurement and plan — runs two weeks. Implementation typically takes two to four months depending on scope and how aggressive the incremental delivery rhythm needs to be. 14-day money-back guarantee, cancel anytime. Work Made for Hire means you own everything shipped.

What I specifically document: the baseline measurements, the root-cause analysis, every architecture decision made during implementation, and the monitoring setup. When the engagement ends, your team can continue without me. That's the point.

Recent proof

A comparable engagement, delivered and documented.

0s → 300msAPI response time
API Performance Optimization

Rescued a slow API that was blocking user growth

Cuez is a live broadcast production tool used by TV teams on air across Europe. I inherited a backend API averaging 3 seconds per response and cut it to 300ms, while reducing infrastructure costs by 40% and leaving the system stable under real production load.

Read the case study

Keep reading

Custom Web Apps: full service details and pricing

Frequently asked questions

The questions prospects ask before they book.

First wins typically ship within 3 to 4 weeks of engagement start. The first 2 weeks are baseline measurement and root-cause analysis; week 3 onwards ships optimizations. Typical first-round improvements: 30 to 50% P95 reduction on the targeted endpoints. Larger improvements — 5 to 10x — require architectural change and take longer. I won't promise a specific number before the baseline audit.

Decided in week 1 using the seven-factor framework. Most often: targeted refactor of 3 to 5 bottleneck endpoints, leaving everything else alone. Occasionally: extraction of specific services using the strangler fig pattern. Full rebuild is rare and only makes sense when the factors align strongly — particularly when the estimated refactor cost approaches 60 to 70% of a rebuild estimate anyway.

That's the standard expectation. I use zero-downtime patterns throughout: blue-green deploys, feature flags, strangler fig extraction, and shadow traffic comparison before any cutover. Cuez and bolttech both maintained 99.9% uptime through their major refactor phases. Downtime risk is a planning and pattern problem, not an inherent property of refactoring.

Yes, unless there's a concrete technical reason to change. Staying within your stack — Laravel, NestJS, Node, Rails — means your team can maintain the system independently after the engagement. A stack change is only recommended when the stack itself is measurably the bottleneck, which is rarer than teams expect. Language rewrites almost never produce the latency gains that architectural and query fixes do.

P95 and P99 latency per endpoint, throughput in requests per second at target latency, infrastructure cost per transaction, and error rate under load. Before-and-after comparisons are shipped weekly against the baseline. All numbers come from production APM, not staging benchmarks — staging performance doesn't predict production behavior reliably.

In most cases I've worked on, slow queries are the culprit — not application logic. N+1 patterns, missing indexes, and connection pool exhaustion can add hundreds of milliseconds without appearing obviously in application logs. The slow query log and EXPLAIN plans reveal the actual cost. Fixing the query is almost always faster and more durable than refactoring the code around it.

Adriano Junior

Ready to talk about your project?

Tap to text me, call me, or send a message. I reply within minutes.

Adriano Junior

Senior Software Engineer & Consultant. 17+ years building websites, apps, and AI that ship.

Services

  • MVP Development
  • Custom Web Applications
  • Fractional CTO
  • AI Automation
  • Website Design & Development

Explore

  • Articles & Guides
  • Case Studies
  • About
  • Apps
  • Curriculum
  • Contact

© 2009–2026 Adriano Junior. All rights reserved.

Privacy PolicySitemap