Overview
The Challenge
- Slow performance: 5.8s LCP killing mobile conversions
- Complex checkout: Prescription meds require validation, insurance auth, and compliance
- Scaling pain: Legacy React codebase couldn't handle traffic spikes
- Poor DX: 8+ minute build times slowing feature delivery
Key Results
| Metric | Before | After | Impact |
|---|---|---|---|
| LCP (Largest Contentful Paint) | 5.8s | 2.5s | -56% |
| Conversion Rate | 2.1% | 2.6% | +23% |
| Monthly Transactions | — | $2M+ | — |
| Build Time | 8 min | 2.5 min | -69% |
| Bundle Size | 1.2 MB | 720 KB | -40% |
| Lighthouse Score | 54 | 92 | +70% |
Technical Deep Dive
Performance Optimization
- Migrated 2,000+ product images to Next.js Image with automatic WebP/AVIF
- Implemented blur placeholders for perceived performance
- Lazy loading for below-fold content
- Route-based splitting with dynamic imports
- Separated vendor chunks for better caching
- Deferred non-critical JavaScript (analytics, chat widgets)
- Inlined critical CSS for above-fold content
- Preconnect to essential third-party domains
- Font subsetting and
font-display: swap
Checkout Architecture
- OTC products (no validation needed)
- Prescription medications (requires Rx upload + validation)
- Insurance-covered items (requires real-time auth with carriers)
┌─────────────────────────────────────────────────┐
│ Checkout Flow │
├─────────────────────────────────────────────────┤
│ ┌──────────┐ ┌──────────┐ ┌──────────────┐ │
│ │ Cart │→ │ Address │→ │ Payment │ │
│ │ Module │ │ Module │ │ Module │ │
│ └──────────┘ └──────────┘ └──────────────┘ │
│ ↓ ↓ ↓ │
│ ┌──────────────────────────────────────────┐ │
│ │ Prescription Validator │ │
│ │ (async, non-blocking for OTC) │ │
│ └──────────────────────────────────────────┘ │
│ ↓ │
│ ┌──────────────────────────────────────────┐ │
│ │ Insurance Authorization │ │
│ │ (Sura, GNP, MetLife integrations) │ │
│ └──────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘- Optimistic UI: Show success states while processing in background
- Graceful degradation: If insurance API fails, offer cash price
- State persistence: Save checkout progress to localStorage + server
Payment Processing & Financial Transaction Architecture
- Credit/debit cards (Visa, Mastercard, Amex) with tokenized payment processing
- OXXO cash payments (critical for Mexico's unbanked population)
- Bank transfers (SPEI) with real-time settlement tracking
- Monthly installments (MSI) with automated interest calculation
- Idempotent payment requests: Prevent duplicate charges during network failures
- Payment abstraction layer: Gateway-agnostic interface allowing provider switching without checkout rewrites
- Real-time pricing engine: Dynamic pricing based on insurance coverage, promotions, and inventory levels
- Audit trail: Complete transaction logging for financial compliance and reconciliation
Next.js 15 Migration
- Parallel deployment: New pages in Next.js, legacy in CRA
- Gradual route migration over 3 months
- Zero-downtime cutover using Vercel's preview deployments
- 40% smaller bundle (Server Components)
- 69% faster builds (Turbopack)
- Better SEO with automatic metadata
- Simplified data fetching patterns
Automation & Integrations
- Medical appointment orchestration: Auto-schedule follow-ups based on prescription cycles
- Insurance pre-authorization: Automated document submission to carriers
- Inventory alerts: Notify patients when chronic meds are back in stock
Tech Stack
| Layer | Technology |
|---|---|
| Framework | Next.js 15 (App Router) |
| Language | TypeScript |
| Styling | Tailwind CSS, CSS Modules |
| State | Zustand, React Query |
| Payments | Tonder |
| Analytics | Mixpanel, OpenReplay |
| Automation | N8N |
| Deployment | Vercel |
| Monitoring | Sentry, Vercel Analytics |
Lessons Learned
1. Healthcare ≠ Regular E-commerce
2. Performance = Revenue
3. Modular Architecture Pays Dividends
4. Invest in Developer Experience
Impact
- 15,000+ monthly orders
- 99.9% checkout uptime
- 2.5s average page load (mobile)
- 4.8★ app store rating (related to web experience)
Looking for a senior frontend engineer who understands both code and business impact? Let's talk →
Tell me what's stealing hours from your team
A free 30-minute call, no sales pitch: we review your operation and I tell you whether I can help — and how.Book a call
