<?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: Rahul Rana</title>
    <description>The latest articles on DEV Community by Rahul Rana (@rahul_rana_e18b14ad46c435).</description>
    <link>https://dev.to/rahul_rana_e18b14ad46c435</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%2F2044844%2F92ab3e38-d288-42c9-967e-d50a5b962b6d.jpg</url>
      <title>DEV Community: Rahul Rana</title>
      <link>https://dev.to/rahul_rana_e18b14ad46c435</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rahul_rana_e18b14ad46c435"/>
    <language>en</language>
    <item>
      <title>Building a sub-100ms 50-state tax engine in Next.js (without burning serverless compute)</title>
      <dc:creator>Rahul Rana</dc:creator>
      <pubDate>Wed, 07 Oct 2026 20:41:05 +0000</pubDate>
      <link>https://dev.to/rahul_rana_e18b14ad46c435/building-a-sub-100ms-50-state-tax-engine-in-nextjs-without-burning-serverless-compute-23pe</link>
      <guid>https://dev.to/rahul_rana_e18b14ad46c435/building-a-sub-100ms-50-state-tax-engine-in-nextjs-without-burning-serverless-compute-23pe</guid>
      <description>&lt;p&gt;Most web calculators are slow for bad reasons.&lt;/p&gt;

&lt;p&gt;If you inspect the network tab on popular calculator sites, you will routinely see 40+ JavaScript chunks, multiple ad exchange bidding scripts, and heavy client-side bundles. A page that should take 50 lines of arithmetic ends up taking 3 seconds to become interactive.&lt;/p&gt;

&lt;p&gt;Over the past few weeks, I built PureCalc&lt;br&gt;
, a suite of paycheck and construction calculators. My goal was simple: sub-100ms Time to First Byte (TTFB), zero third-party scripts, and static pre-rendering across thousands of routes.&lt;/p&gt;

&lt;p&gt;Here is how I structured the tax engine, handled state statutory edge cases, and kept serverless compute costs near zero.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Route Generation Problem&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I wanted dedicated, indexable landing pages for specific queries (e.g., /paycheck-calculator/california/75000-a-year or /concrete-calculator/10x10-slab-4-inch).&lt;/p&gt;

&lt;p&gt;Doing this naively with dynamic server-side rendering (SSR) on every request burns serverless execution time and adds cold-start latency.&lt;/p&gt;

&lt;p&gt;Instead, I used Next.js static export via generateStaticParams. We precompute 2,300+ common salary tiers and slab dimensions at build time:&lt;/p&gt;

&lt;p&gt;typescript&lt;br&gt;
// app/paycheck-calculator/[state]/[salary]/page.tsx&lt;br&gt;
export async function generateStaticParams() {&lt;br&gt;
  const states = getAllStates(); // 50 states + DC&lt;br&gt;
  const salaryTiers = [&lt;br&gt;
    25000, 30000, 40000, 50000, 60000, 75000, &lt;br&gt;
    85000, 100000, 125000, 150000, 200000, 250000&lt;br&gt;
  ];&lt;br&gt;
  return states.flatMap((state) =&amp;gt;&lt;br&gt;
    salaryTiers.map((salary) =&amp;gt; ({&lt;br&gt;
      state: state.slug,&lt;br&gt;
      salary: &lt;code&gt;${salary}-a-year&lt;/code&gt;,&lt;br&gt;
    }))&lt;br&gt;
  );&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;By pushing these pages to Vercel's edge cache (s-maxage=31536000), the edge network serves pure static HTML in 65ms. Origin compute only wakes up when a user types an unusual custom number that wasn't in the static build.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Modeling 50 State Tax Engines Cleanly&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;US income taxes look simple on paper, but state-level exceptions quickly create messy code if you don't structure the data cleanly.&lt;/p&gt;

&lt;p&gt;Instead of writing custom conditional logic per state, I separated the engine into three steps:&lt;/p&gt;

&lt;p&gt;Federal Taxable Income (Standard deductions, FICA caps).&lt;br&gt;
State Marginal Brackets (or flat tax rates).&lt;br&gt;
Mandatory State Statutory Deductions (SDI, Paid Family Leave, Unemployment).&lt;/p&gt;

&lt;p&gt;Here is the TypeScript interface that keeps the engine organized:&lt;/p&gt;

&lt;p&gt;typescript&lt;br&gt;
export interface StateTaxConfig {&lt;br&gt;
  stateCode: string;&lt;br&gt;
  name: string;&lt;br&gt;
  type: 'none' | 'flat' | 'progressive';&lt;br&gt;
  flatRate?: number;&lt;br&gt;
  brackets?: TaxBracket[];&lt;br&gt;
  standardDeduction: {&lt;br&gt;
    single: number;&lt;br&gt;
    married: number;&lt;br&gt;
  };&lt;br&gt;
  statutoryDeductions?: StatutoryDeduction[];&lt;br&gt;
}&lt;br&gt;
export interface StatutoryDeduction {&lt;br&gt;
  name: string;&lt;br&gt;
  rate: number;&lt;br&gt;
  wageCap?: number; // e.g. Social Security wage limit&lt;br&gt;
  uncapped: boolean; // e.g. CA SDI is now uncapped&lt;br&gt;
}&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Trap: Hidden Statutory Deductions&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you only calculate state income tax, your take-home pay numbers will be wrong for several major states.&lt;/p&gt;

&lt;p&gt;A few real-world examples:&lt;/p&gt;

&lt;p&gt;California SDI: In 2024, California removed the wage cap on State Disability Insurance. It is a flat 1.30% deduction on all gross wages with zero ceiling. If you earn $300k, you pay $3,900 in SDI.&lt;br&gt;
Washington Cares Fund: Washington has no state income tax, but it mandates a 0.58% long-term care payroll tax on gross wages, plus Paid Family and Medical Leave (PFML).&lt;br&gt;
Pennsylvania UC: In addition to its 3.07% flat income tax, Pennsylvania withholds 0.07% for state employee unemployment compensation.&lt;/p&gt;

&lt;p&gt;To handle these, the engine loops through statutory rules independently of the income tax bracket calculation:&lt;/p&gt;

&lt;p&gt;typescript&lt;br&gt;
export function calculateStatutoryWithholding(&lt;br&gt;
  grossIncome: number, &lt;br&gt;
  deductions: StatutoryDeduction[]&lt;br&gt;
): Record {&lt;br&gt;
  const result: Record = {};&lt;br&gt;
  for (const item of deductions) {&lt;br&gt;
    const taxableBase = item.uncapped &lt;br&gt;
      ? grossIncome &lt;br&gt;
      : Math.min(grossIncome, item.wageCap ?? grossIncome);&lt;br&gt;
    result[item.name] = Math.round(taxableBase * item.rate * 100) / 100;&lt;br&gt;
  }&lt;br&gt;
  return result;&lt;br&gt;
}&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Why Whole-Bag Ceiling Math Matters&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;On the construction calculator side, floating-point math causes practical problems if you don't account for real-world hardware store constraints.&lt;/p&gt;

&lt;p&gt;When calculating concrete bags for a slab: Volume = (Length * Width * Depth_in_feet) / 27&lt;/p&gt;

&lt;p&gt;If you calculate a 10x10 ft slab at 4 inches thick:&lt;/p&gt;

&lt;p&gt;Base volume = 1.23 cubic yards.&lt;br&gt;
Add 10% for ground unevenness = 1.36 cubic yards (36.67 cubic feet).&lt;br&gt;
An 80 lb bag yields 0.60 cubic feet.&lt;br&gt;
36.67 / 0.60 = 61.11 bags.&lt;/p&gt;

&lt;p&gt;If your code runs standard Math.round(), it returns 61 bags. But if a homeowner buys 61 bags, they run out of concrete before filling the forms.&lt;/p&gt;

&lt;p&gt;We always apply Math.ceil() to the bag calculation after applying waste:&lt;/p&gt;

&lt;p&gt;typescript&lt;br&gt;
export function calculateBagCounts(cubicYardsWithWaste: number) {&lt;br&gt;
  const cubicFeet = cubicYardsWithWaste * 27;&lt;br&gt;
  return {&lt;br&gt;
    bags80lb: Math.ceil(cubicFeet / 0.60),&lt;br&gt;
    bags60lb: Math.ceil(cubicFeet / 0.45),&lt;br&gt;
    bags40lb: Math.ceil(cubicFeet / 0.30),&lt;br&gt;
  };&lt;br&gt;
}&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Results &amp;amp; Telemetry&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By keeping the frontend lean and eliminating ad network scripts:&lt;/p&gt;

&lt;p&gt;Payload size: ~12 KB compressed HTML.&lt;br&gt;
Edge TTFB: 64ms to 85ms across US regions.&lt;br&gt;
Cumulative Layout Shift (CLS): 0.00.&lt;br&gt;
First Contentful Paint (FCP): &amp;lt; 0.4s on mobile 4G.&lt;/p&gt;

&lt;p&gt;You can inspect the live tools and test scenarios at purecalchq.com&lt;br&gt;
.&lt;/p&gt;

&lt;p&gt;If anyone is working on multi-jurisdiction tax engines or has feedback on local municipal wage taxes (like Philadelphia or Detroit resident surcharges), I would love to connect.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
