# Multi-PoP Latency Map

URL: /docs/experiments/multi-pop-latency-map
> Measure fetch latency and report the Cloudflare colo that served the Worker - edge PoP latency visibility for any URL
Tags: network, latency, colo, performance, pop, monitoring
Markdown: /llms.mdx/experiments/multi-pop-latency-map/content.md



Fetch a target URL from the edge and report response time plus the **Cloudflare colo** (`cf.colo`) that handled the Worker invocation. Documents honestly that each request runs in a **single PoP** - not a global multi-region sweep.

## Features [#features]

* **GET /latency?url=** - Response time, status code, and edge location
* **Colo metadata** - `colo`, `city`, `country` from `request.cf`
* **Transparent limitations** - Response includes `limitation` and `tip` fields
* **Cache bypass** - Uses `cf: { cacheTtl: 0 }` on the outbound fetch

## API Reference [#api-reference]

### GET /latency [#get-latency]

Measure fetch latency from the current edge location.

<TypeTable
  type="{
  url: {
    description: &#x22;Target URL (http or https only).&#x22;,
    type: &#x22;string&#x22;,
    required: true,
  },
}"
/>

#### Example Request [#example-request]

```bash
curl "https://your-worker.workers.dev/latency?url=https://www.cloudflare.com"
```

#### Success Response [#success-response]

```json
{
  "url": "https://www.cloudflare.com/",
  "responseTimeMs": 87,
  "statusCode": 200,
  "colo": "SFO",
  "city": "San Francisco",
  "country": "US",
  "timestamp": "2025-06-20T12:00:00.000Z",
  "limitation": "Each Worker invocation runs in a single Cloudflare PoP...",
  "tip": "For multi-region comparison, call this endpoint repeatedly from different client locations..."
}
```

#### Error Codes [#error-codes]

* `400` - Invalid URL (`INVALID_URL`)
* `502` - Fetch failed (`FETCH_ERROR`)

<Callout type="warning">
  This endpoint reports latency from **one PoP per request**. It does not perform a simultaneous multi-region ping. Call repeatedly from different geographic clients to compare colos.
</Callout>

## Use Cases [#use-cases]

* Show students how `request.cf.colo` identifies the serving edge
* Compare latency when calling the worker from different client locations
* Learn honest edge networking constraints in Workers

## Limitations [#limitations]

* Single PoP per invocation; no built-in multi-region orchestration
* `colo` reflects where the Worker ran, not every hop to the origin
* Outbound fetch timing includes DNS + TLS + TTFB for the target URL

## Use in your project [#use-in-your-project]

<UseInYourProject
  experiment="multi-pop-latency-map"
  platform="[&#x22;Workers runtime&#x22;]"
  files="[
  &#x22;src/lib/url.ts&#x22;,
  &#x22;src/constants/defaults.ts&#x22;,
  &#x22;examples/usage.ts&#x22;,
]"
  sources="[{&#x22;path&#x22;:&#x22;src/lib/url.ts&#x22;,&#x22;title&#x22;:&#x22;url.ts&#x22;,&#x22;lang&#x22;:&#x22;ts&#x22;,&#x22;code&#x22;:&#x22;import { ALLOWED_SCHEMES } from \&#x22;../constants/defaults\&#x22;;\n\nexport function validateUrl(input: string | undefined): string | null {\n  if (!input || typeof input !== \&#x22;string\&#x22;) return null;\n  const trimmed = input.trim();\n  if (!trimmed) return null;\n  try {\n    const url = new URL(trimmed);\n    if (!ALLOWED_SCHEMES.includes(url.protocol as (typeof ALLOWED_SCHEMES)[number])) {\n      return null;\n    }\n    return url.href;\n  } catch {\n    return null;\n  }\n}\n\nexport function getCfLocation(cf: { colo?: string; city?: string; country?: string } | undefined) {\n  return {\n    colo: cf?.colo ?? null,\n    city: cf?.city ?? null,\n    country: cf?.country ?? null,\n  };\n}&#x22;},{&#x22;path&#x22;:&#x22;src/constants/defaults.ts&#x22;,&#x22;title&#x22;:&#x22;defaults.ts&#x22;,&#x22;lang&#x22;:&#x22;ts&#x22;,&#x22;code&#x22;:&#x22;export const ALLOWED_SCHEMES = [\&#x22;http:\&#x22;, \&#x22;https:\&#x22;] as const;\n\nexport const POP_LIMITATION =\n  \&#x22;Each Worker invocation runs in a single Cloudflare PoP. This endpoint reports latency from the PoP that handled your request, not a global multi-region sweep.\&#x22;;\n\nexport const POP_TIP =\n  \&#x22;For multi-region comparison, call this endpoint repeatedly from different client locations or use Cloudflare's own observability tools.\&#x22;;&#x22;},{&#x22;path&#x22;:&#x22;examples/usage.ts&#x22;,&#x22;title&#x22;:&#x22;usage.ts&#x22;,&#x22;lang&#x22;:&#x22;ts&#x22;,&#x22;code&#x22;:&#x22;/**\n * Minimal paste example for docs (\&#x22;Use in your project\&#x22;).\n * Not part of the Worker runtime — copy into your own project.\n *\n * Typical API: GET /latency?url=https://example.com\n */\nimport { validateUrl } from \&#x22;../src/lib/url\&#x22;;\nimport { validateUrl } from \&#x22;../src/lib/url\&#x22;;\n\nexport default {\n  async fetch(request: Request): Promise<Response> {\n    const raw = new URL(request.url).searchParams.get(\&#x22;url\&#x22;);\n    const url = validateUrl(raw ?? undefined);\n    if (!url) {\n      return Response.json({ error: \&#x22;Missing or invalid url\&#x22;, code: \&#x22;INVALID_URL\&#x22; }, { status: 400 });\n    }\n    const result = validateUrl(url);\n    return Response.json(result);\n  },\n};&#x22;}]"
/>

## Deployment [#deployment]

<Steps>
  <Step>
    ### Click the deploy button [#click-the-deploy-button]

    [![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/shrinathsnayak/cloudflare-experiments/tree/main/apps/experiments/multi-pop-latency-map)
  </Step>

  <Step>
    ### Test your deployment [#test-your-deployment]

    ```bash
    curl "https://your-worker.workers.dev/latency?url=https://example.com"
    ```
  </Step>
</Steps>

## Local Development [#local-development]

```bash
cd apps/experiments/multi-pop-latency-map
npm install
npm run dev
```

<Callout>
  `colo` and geolocation fields are populated when deployed to Cloudflare's edge. Local `wrangler dev` may return null for some `cf` properties.
</Callout>

## Cloudflare Features Used [#cloudflare-features-used]

* **[Workers](https://developers.cloudflare.com/workers/)** - Edge compute runtime
* **`request.cf`** - Colo and geolocation metadata
* **Fetch API** - Outbound HTTP with cache controls
