---
id: "reconnect-stampede-without-guard"
type: "rule"
severity: "error"
url: "https://localhost:3000/catalogue/rules/reconnect-stampede-without-guard"
---

# Reconnect stampede without guard

A realtime gateway calls a coordination service synchronously on connect and has no guard against a mass reconnect.

| | |
|---|---|
| Severity | error |
| Selects | every node of kind realtime-gateway |
| Components in scope | 20 |

## Why

When a gateway holding millions of sockets restarts, every client reconnects at once and the gateway asks the coordination service about each of them. Without a stampede guard that lookup storm takes the coordination service down too.

## What it checks

It looks at every node of kind realtime-gateway, and fires when:

- all of these hold:
  - the node has at least one synchronous outgoing edge to a coordination-service
  - the node's `stampedeGuard` is false

Message template:

```
Realtime gateway '{{node.id}}' calls a coordination service synchronously on connect but has no reconnect stampede guard.
```

## Applies to

- [Real-time gateway](https://localhost:3000/catalogue/kinds/realtime-gateway.md) `realtime-gateway`

20 catalogue components fall under it.

## Tripped by

Reference designs whose broken twin names this rule in its header:

- [discord-messages](https://localhost:3000/d/zeema/discord-messages)
- [facebook-messenger](https://localhost:3000/d/zeema/facebook-messenger)
- [nearby-friends](https://localhost:3000/d/zeema/nearby-friends)
- [slack-messaging](https://localhost:3000/d/zeema/slack-messaging)
- [uber-dispatch](https://localhost:3000/d/zeema/uber-dispatch)

## Source (`rule` YAML, verbatim)

```yaml
# yaml-language-server: $schema=../schema/rule.schema.json
# When a gateway holding millions of sockets restarts, every client reconnects at once
# and the gateway hits the coordination service (discovery, ring lookup) for each of them.
# Without a stampede guard (jittered reconnect, connection admission) that lookup storm
# takes the coordination service down with it.
# Tripped by: designs/slack-messaging.broken.yaml
schemaVersion: "1"
type: "rule"
id: "reconnect-stampede-without-guard"
severity: "error"
select:
  node:
    kind: "realtime-gateway"
when:
  all:
    - hasEdge:
        direction: "out"
        mode: "sync"
        peerKind: "coordination-service"
    - prop: "stampedeGuard"
      equals: false
message: "Realtime gateway '{{node.id}}' calls a coordination service synchronously on connect but has no reconnect stampede guard."
```

Human page: https://localhost:3000/catalogue/rules/reconnect-stampede-without-guard
