Components that render on server, send HTML to client, never hydrate
Zero JavaScript bundle, direct backend access, streaming
Client Components
'use client'
Traditional React components with interactivity, hooks, browser APIs
Explicit boundary for client-side JavaScript
Async Components
await fetch()
Server components can be async, directly fetch data without useEffect
Cleaner code, automatic request deduplication
Streaming SSR
<Suspense>
Send HTML progressively as components render, show fallback for slow parts
Faster Time to First Byte (TTFB), progressive enhancement
Server Actions BETA
'use server'
Functions that run on server, called from client components like RPC
Type-safe server mutations, no API routes needed
Example: Server Components with Streaming
// app/page.js - Server Component (default)export default async function Page() { // Direct database/API access, no client bundle impact const data = await db.query('SELECT * FROM posts'); return ( <main> <h1>Posts</h1> <Suspense fallback={<Loading />}> <PostList data={data} /> </Suspense> </main> );}// components/InteractiveButton.js - Client Component'use client';import { useState } from 'react';export default function InteractiveButton() { const [count, setCount] = useState(0); return <button onClick={() => setCount(c => c + 1)}>{count}</button>;}// Server Actionasync function createPost(formData) { 'use server'; const title = formData.get('title'); await db.insert({ title }); revalidatePath('/posts');}
Important: Server Components cannot use browser APIs, hooks (useState, useEffect), or event
handlers. Use 'use client' directive for interactive components.
6. Edge-First Architecture Vercel
Concept
Platform
Description
Use Case
Edge Functions
Vercel, Cloudflare Workers
Lightweight serverless functions running at CDN edge locations globally
Low-latency API responses, personalization, A/B testing
Edge Middleware
middleware.js
Intercept requests before they reach application, run logic at edge
Subset of Node.js APIs, optimized for fast cold starts (<10ms)
Dynamic rendering near users, streaming responses
Incremental Static Regeneration
revalidate
Static pages regenerate at edge on-demand, cached globally
E-commerce, content sites with frequent updates
Edge Config
@vercel/edge-config
Ultra-fast key-value store accessible from edge functions (<1ms reads)
Feature flags, A/B test configs, redirects
Example: Next.js Edge Middleware
// middleware.js - Runs at edge for all routesimport { NextResponse } from 'next/server';export function middleware(request) { // Geolocation-based redirect const country = request.geo?.country; if (country === 'US') { return NextResponse.redirect(new URL('/us', request.url)); } // A/B testing const bucket = Math.random() < 0.5 ? 'a' : 'b'; const response = NextResponse.next(); response.cookies.set('bucket', bucket); // Authentication check const token = request.cookies.get('session'); if (!token && request.nextUrl.pathname.startsWith('/dashboard')) { return NextResponse.redirect(new URL('/login', request.url)); } return response;}export const config = { matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)']};
Edge vs Serverless
Metric
Edge
Serverless
Cold Start
<10ms
100-500ms
Location
Global CDN
Regional
Runtime
V8 Isolate
Node.js
APIs
Web Standard
Full Node.js
Edge Use Cases
Authentication & authorization
Bot detection & rate limiting
A/B testing & feature flags
Geolocation redirects
Personalized content
SEO optimizations
Request/response transformation
Cache control headers
Performance Benefit: Edge-first architecture reduces latency by 50-90% compared to traditional
origin servers by serving content from locations close to users.