|
| 1 | +--- |
| 2 | +id: '1760817947' |
| 3 | +title: Prefer Structured URLs Over Flat URLs |
| 4 | +state: Draft |
| 5 | +created: 2025-10-18 |
| 6 | +tags: [url-design, architecture, performance, seo] |
| 7 | +category: Platform |
| 8 | +--- |
| 9 | + |
| 10 | +# Prefer Structured URLs Over Flat URLs |
| 11 | + |
| 12 | +## Context |
| 13 | + |
| 14 | +URL design is often treated as a purely aesthetic or SEO decision. Teams favor |
| 15 | +"clean" flat URLs like `/nike-air-zoom` over structured URLs like |
| 16 | +`/product/nike-air-zoom`. However, flat URLs have significant architectural |
| 17 | +costs that are often overlooked. |
| 18 | + |
| 19 | +With flat URLs, applications cannot determine the entity type from the path |
| 20 | +alone, requiring resolution queries: |
| 21 | + |
| 22 | +```javascript |
| 23 | +// Flat URL - requires resolution |
| 24 | +const slug = path.split('/')[1]; |
| 25 | + |
| 26 | +const product = await getProduct(slug); |
| 27 | +if (product) return renderProduct(product); |
| 28 | + |
| 29 | +const category = await getCategory(slug); |
| 30 | +if (category) return renderCategory(category); |
| 31 | + |
| 32 | +return render404(); |
| 33 | +``` |
| 34 | + |
| 35 | +With structured URLs, routing is deterministic — no resolution needed: |
| 36 | + |
| 37 | +```javascript |
| 38 | +// Structured URL - instant routing |
| 39 | +const prefix = path.split('/')[1]; // "product" |
| 40 | +// Route directly to product handler |
| 41 | +``` |
| 42 | + |
| 43 | +A case study documented the real-world impact: every page required 2 backend |
| 44 | +calls (one succeeds, one fails), 404s wasted 2 calls each, and infrastructure |
| 45 | +costs were 40% higher than projected. |
| 46 | + |
| 47 | +Flat URLs also require enforcing slug uniqueness across all entity types at the |
| 48 | +database level — a product and category cannot share the same slug. Structured |
| 49 | +URLs allow independent namespaces per type. |
| 50 | + |
| 51 | +## Resolution |
| 52 | + |
| 53 | +- You **SHOULD** use structured/prefixed URLs for new projects (e.g., `/p/slug` or `/product/slug`). |
| 54 | + |
| 55 | +## Links |
| 56 | + |
| 57 | +- [The Hidden Cost of URL Design](https://alfy.blog/2025/10/16/hidden-cost-of-url-design.html) - Case study referenced in Context |
0 commit comments