# HTTP 503 Service Unavailable：由于重平衡，Connect REST API暂时不可用

- **ID:** `kafka/connect-rest-api-503-service-unavailable`
- **领域:** kafka
- **类别:** network_error
- **错误码:** `503`
- **验证级别:** ai_generated
- **修复率:** 79%

## 根因

当集群正在进行重平衡时，Kafka Connect的REST API返回503，因为工作节点领导权可能正在重新分配，端点被暂时禁用。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kafka 3.4.0 | active | — | — |
| Kafka 3.5.1 | active | — | — |
| Kafka 3.7.0 | active | — | — |

## 解决方案

1. ```
   Implement retry logic with exponential backoff in your client. Example in Python: import time; for i in range(5): try: response = requests.get('http://connect-host:8083/connectors'); break; except requests.exceptions.HTTPError as e: if e.response.status_code == 503: time.sleep(2**i); else: raise
   ```
2. ```
   Monitor the rebalance status using Kafka's metrics or logs, and only query the REST API after the rebalance completes. Check for 'REBALANCE_COMPLETED' log entries.
   ```

## 无效尝试

- **Setting 'rest.advertised.host.name' to a different value** — Increasing worker timeout does not prevent the 503 during rebalance; the API is intentionally disabled. (90% 失败率)
- **Restarting a single Connect worker** — Restarting one worker may trigger another rebalance, making the 503 persist longer. (85% 失败率)
