---
name: ipv6-destination-selection
description: >
  Use when services publish multiple A or AAAA records, DNS round-robin appears to
  fail, backends are uneven, or clients implement load balancing, gai.conf policy,
  gRPC or HTTP/2 connection pools. Handles RFC 6724 Rule 9 and within-family spreading
  for dual-stack and IPv6-only data centers.
---

# IPv6 destination selection

## Instructions

Assume the client already has the full address list (`ipv6-name-resolution`).

1. Partition candidates by address family.
2. Apply family preference (IPv6-first / Happy Eyeballs). Do **not** shuffle IPv4 and IPv6 together.
3. For equivalent data-center backends, randomize or weight **within** each family. Do not trust DNS or `getaddrinfo` order for spread after RFC 6724 Rule 9.
4. Refresh on DNS TTL expiry or from service discovery so membership stays current.
5. For long-lived HTTP/2 / gRPC pools, remember selection often happens only at connect time; connection count ≠ request count after membership changes.
6. Prefer putting this logic in a shared client library.

## Gotchas

- Rule 9 ("longest matching prefix") can collapse same-family DNS round-robin to one preferred address — often worse on IPv6 inside a DC.
- Changing `/etc/gai.conf` does not fully disable Rule 9 in all implementations.
- Taking only `result->ai_addr` / the first language result defeats multi-record designs.
- External Internet destinations: keep RFC 6724 / Happy Eyeballs family order; still do not treat DNS order as LB while Rule 9 runs.

## Pattern

```
resolve all → partition by family → HE / family preference
  → within-family random or weighted → retry across set on failure
```

## Sibling skills

- `ipv6-name-resolution`
- `ipv6-ready-coding`
- `ipv6-code-review`

## Source

- Hub: https://www.peachymango.org/ipv6
- Draft anchors: `#address-selection`, `#client-load-balancing`
- Related: https://datatracker.ietf.org/doc/draft-martin-ipv6-addr-selection-updates/
- https://datatracker.ietf.org/doc/draft-martin-deploying-ipv6-data-center/
