NexaPay
    Back to Blog
    Engineering

    Optimizing React Server Components for Sub-50ms Payment Latency

    A deep dive into how NexaPay engineered its new checkout flow to handle 10,000 requests per second

    David Chen

    David Chen

    Chief Technology Officer

    January 21, 202618 min read
    Optimizing React Server Components for Sub-50ms Payment Latency

    Key Takeaways

    • P99 latency reduced from 340ms to 47ms through RSC optimization
    • Edge deployment across 47 PoPs ensures <100ms global latency
    • Streaming SSR reduced Time to First Byte by 62%
    • Custom connection pooling increased throughput 4.2x

    Every 100ms of latency in checkout costs approximately 1% in conversion rate. For a merchant processing $100M annually, that's $1M left on the table. This reality drove our complete architectural overhaul in Q3 2025.

    The Legacy Architecture

    Our previous checkout was a standard React SPA with client-side data fetching. The flow was straightforward but slow: initial HTML shell, JavaScript bundle download, hydration, API calls for payment methods, then render.

    // Old approach: 340ms average latency
    const PaymentForm = () => {
      const [methods, setMethods] = useState([]);
      useEffect(() => {
        fetch('/api/payment-methods')
          .then(r => r.json())
          .then(setMethods);
      }, []);
      // Render after data loads...
    };

    The waterfall was brutal. Users stared at loading spinners while we made three sequential API calls before showing a single input field.

    The RSC Transformation

    React Server Components fundamentally changed our architecture. Payment method fetching, fraud scoring, and personalization now happen on the server, streaming HTML directly to the browser.

    // New approach: 47ms P99 latency
    async function PaymentForm({ merchantId }) {
      const methods = await getPaymentMethods(merchantId);
      const riskScore = await calculateRisk(merchantId);
      
      return (
        <Suspense fallback={<FormSkeleton />}>
          <StreamingPaymentFields 
            methods={methods}
            riskLevel={riskScore}
          />
        </Suspense>
      );
    }

    The moment we deployed RSC, our conversion rate jumped 3.2%. Nothing else changed—just faster rendering.

    Edge Deployment Strategy

    Server components only matter if the server is close to users. We deployed our checkout across 47 edge locations using Cloudflare Workers, ensuring sub-50ms latency for 94% of global traffic.

    • Primary regions: US-East, US-West, Frankfurt, Singapore, São Paulo
    • Secondary regions: 42 additional PoPs for tail latency optimization
    • Smart routing based on real-time latency measurements
    David Chen

    Written by David Chen

    Chief Technology Officer