# Rate limits

Turn on Jira's per-endpoint and per-issue write limits, so a request past a limit returns Jira's 429 with Retry-After.

Test how your integration backs off when Jira refuses a request for speed. Every response from an endpoint the simulator serves includes Jira's rate-limit headers, here on the default scenario:

```bash
curl -s -D - -o /dev/null -u me@example.com:token "$RYSTIC_URL/rest/api/3/myself" | tr -d '\r' | grep -i -E '^(x-ratelimit|ratelimit)'
# -> RateLimit-Policy: "jira-burst-based";q=100;w=1
# -> X-RateLimit-Limit: 350
# -> X-RateLimit-Remaining: 349
```

`q` is the endpoint's rate a second, `X-RateLimit-Limit` the most requests its allowance holds and `X-RateLimit-Remaining` what is left of it. The count goes down even with no setting. The assignee edit endpoint refills 50 a second (`q=50`), so two edits in one curl process leave one fewer each time:

```bash
ISSUE="$RYSTIC_URL/rest/api/3/issue/PLAT-1/assignee"
curl -s -D - -u me@example.com:token -X PUT -H 'Content-Type: application/json' -d '{"accountId":null}' -o /dev/null "$ISSUE" -o /dev/null "$ISSUE" | tr -d '\r' | grep -i -E '^(x-ratelimit-remaining|ratelimit-policy)'
# -> RateLimit-Policy: "jira-burst-based";q=50;w=1
# -> X-RateLimit-Remaining: 299
# -> RateLimit-Policy: "jira-burst-based";q=50;w=1
# -> X-RateLimit-Remaining: 298
```

With no setting nothing is refused, so 23 more writes to the issue all succeed:

```bash
curl -s -u me@example.com:token -X PUT -H 'Content-Type: application/json' -d '{"accountId":null}' -w '%{http_code}\n' $(for i in $(seq 23); do echo "-o /dev/null $ISSUE"; done) | sort | uniq -c | awk '{print $2, $1}'
# -> 204 23
```

Setting [`rate_limits: real`](https://www.rystic.ai/docs/network-profiles.md) turns on the per-endpoint and per-issue limits in the [Rate limits](https://www.rystic.ai/docs/simulators/jira.md#rate-limits) table. An issue takes 20 writes in 2 seconds, and that window opens at its first write. Turn the limits on, reload the scenario to start from full allowances and send the same 23 writes over one connection:

```bash
curl -s -X POST "$RYSTIC_URL/_rystic/network" -o /dev/null -w '%{http_code}\n' -d '{"rate_limits": "real"}'
# -> 204
curl -s -X POST "$RYSTIC_URL/_rystic/scenario" -o /dev/null -w '%{http_code}\n' -d '{"name": "jira_sprint_board"}'
# -> 204
curl -s -u me@example.com:token -X PUT -H 'Content-Type: application/json' -d '{"accountId":null}' -w '%{http_code}\n' $(for i in $(seq 23); do echo "-o /dev/null $ISSUE"; done) | sort | uniq -c | awk '{print $2, $1}'
# -> 204 20
# -> 429 3
curl -s -D - -o /dev/null -u me@example.com:token -X PUT -H 'Content-Type: application/json' -d '{"accountId":null}' "$ISSUE" | tr -d '\r' | grep -i '^retry-after'
# -> Retry-After: 2
curl -s -u me@example.com:token -X PUT -H 'Content-Type: application/json' -d '{"accountId":null}' "$ISSUE" | jq -c .
# -> {"errorMessages":["Rate limit exceeded."],"errors":{}}
curl -s -u me@example.com:token -X PUT -H 'Content-Type: application/json' -d '{"accountId":null}' -o /dev/null -w '%{http_code}\n' "$RYSTIC_URL/rest/api/3/issue/PLAT-2/assignee"
# -> 204
```

`Retry-After` is the whole seconds until the issue's window ends. Another issue keeps its own allowance, so the write to `PLAT-2` succeeds. A reset keeps the setting, and loading the scenario again restores every allowance:

```bash
curl -s -X POST "$RYSTIC_URL/_rystic/reset" -o /dev/null -w '%{http_code}\n'
# -> 204
curl -s "$RYSTIC_URL/_rystic/network" | jq -r .rate_limits
# -> real
curl -s -X POST "$RYSTIC_URL/_rystic/scenario" -o /dev/null -w '%{http_code}\n' -d '{"name": "jira_sprint_board"}'
# -> 204
curl -s -u me@example.com:token -X PUT -H 'Content-Type: application/json' -d '{"accountId":null}' -o /dev/null -w '%{http_code}\n' "$ISSUE"
# -> 204
```

---

Source: https://www.rystic.ai/docs/simulators/jira/features/rate-limits · Markdown: https://www.rystic.ai/docs/simulators/jira/features/rate-limits.md
