Skip to content

feat: add /ready endpoint gated on minimum nodes per region - #2539

Draft
aantti wants to merge 2 commits into
mainfrom
feat/readiness-min-nodes-per-region
Draft

aantti wants to merge 2 commits into
mainfrom
feat/readiness-min-nodes-per-region

Conversation

@aantti

@aantti aantti commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

A new, opt-in readiness endpoint, GET /ready, that holds a node out of rotation until its cluster has a minimum number of nodes in every listed region.

What is the current behavior?

/healthcheck returns 200 as soon as the node serves HTTP, and keeps returning 200 while it drains after SIGTERM. In a release where a new set of nodes forms its own cluster, those nodes can take traffic before every region has nodes in the new cluster. Tenants mapped to a region with no node yet are then served from another region.

What is the new behavior?

  • READINESS_MIN_NODES_PER_REGION, e.g. us-east-1=2,eu-west-1=2: /ready returns 503 not ready until the node's cluster has at least that many nodes in each listed region, counted from the RegionNodes scope (the node itself included). Then it returns 200.
  • Latch: once ready, it stays ready. A region dropping below its minimum later doesn't take the other nodes out of rotation.
  • After SIGTERM: 503 shutting down.
  • Unset: /ready returns 200 until SIGTERM.
  • /healthcheck doesn't change.
  • Logging: the response doesn't say what the node waits for; the log does. It logs once when the node starts waiting, again only when that changes (a node joins), and once when it is ready, so frequent health checks add no log lines. /ready requests follow DISABLE_HEALTHCHECK_LOGGING, like /healthcheck, and a 503 from /ready is logged at info, not error.
  • Config: malformed pairs, a value that isn't a positive integer, or a repeated region fail at boot (Realtime.Env.get_key_positive_integer_list/1).

Backward compatibility

Opt-in. With READINESS_MIN_NODES_PER_REGION unset or empty, nothing that exists today changes:

  • /healthcheck: unchanged, response and logging alike.
  • /ready: new, previously a 404. It returns 200, or 503 shutting down after SIGTERM, and nothing calls it until a health check is pointed at it.
  • Readiness checks: none run, no nodes are counted, and nothing is logged.
  • A wrongly set value (a malformed pair, a value that isn't a positive integer, a repeated region) fails at boot rather than being ignored.

Additional context

  • Tests: Realtime.Readiness (thresholds, the latch, SIGTERM, log once per change), the controller, and the env parser. mix test on the touched modules, credo, format, sobelow, dialyzer.
  • Tried on a local multi-node setup with two values of REGION. With one region's new nodes held back for 60 s, no node of the new cluster reported ready in either region, and the previous nodes kept serving. Each waiting node logged one line in those 60 s (checked every 5 s), and one more when it turned ready. Once the held region had its minimum, all new nodes turned ready within a few seconds.
  • The 503 after SIGTERM is visible only briefly: at SIGTERM Phoenix drains websockets (batches of 10,000 every 2 s), then Cowboy suspends its listener and new connections are refused. A node with up to 10,000 sockets went from 200 to connection refused within 0.2 s. Either way, a draining node is never ready again.
  • Open question: with many regions, gating on every region means one region short of nodes holds back the whole release (by design here). Other options would be the master region plus the node's own region, or only the regions of the tenants a node would own. Happy to change it.

🤖 Generated with Claude Code


Closes REAL-1370

GET /ready returns 503 until the node's cluster has the minimum number of
nodes in every region listed in READINESS_MIN_NODES_PER_REGION
(e.g. "us-east-1=2,eu-west-1=2"), then 200. Once reached it stays ready, so a
region dropping below its minimum later does not take the other nodes out of
rotation. After SIGTERM it returns 503, so a load balancer stops sending new
connections while the node drains. Unset, /ready is 200 until SIGTERM.

The response says only "not ready" (or "shutting down"); what the node waits
for is logged, once when it starts waiting, again only when that changes,
and once when it is ready, so frequent probes add no log lines. /ready
requests follow DISABLE_HEALTHCHECK_LOGGING, as /healthcheck.

/healthcheck is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aantti aantti self-assigned this Nov 10, 2026
…p a node

syn removes a member asynchronously when its process exits, so asserting
right after stop_supervised raced on a busy runner, and a fake node left by
one test could count toward another test's region. Each test now uses a
region of its own, and the latch test waits for the node to leave.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

CRAP Score Report

Summary: files=266 functions=1526 scored=1526 worst_score=15944.76

** (Mix) CRAP threshold failed: max_score=30.00
High scores: 30
  lib/extensions/postgres_cdc_rls/subscription_manager.ex Extensions.PostgresCdcRls.SubscriptionManager.handle_info/2 score=37.84
  lib/realtime/adapters/postgres/oid_database.ex Realtime.Adapters.Postgres.OidDatabase.name_for_type_id/1 score=15944.76
  lib/realtime/application.ex Realtime.Application.setup_region_mapping/0 score=47.11
  lib/realtime/nodes.ex Realtime.Nodes.default_region_mapping/1 score=129.85
  lib/realtime/operations.ex Realtime.Operations.rebalance/0 score=42.00
  lib/realtime/operations.ex Realtime.Operations.kill_connections_to_tenant_id/2 score=90.00
  lib/realtime/tenants/connect.ex Realtime.Tenants.Connect.handle_info/2 score=42.56
  lib/realtime_web/channels/auth/jwt_verification.ex RealtimeWeb.JwtVerification.generate_signer/3 score=30.78
  lib/realtime_web/channels/realtime_channel.ex RealtimeWeb.RealtimeChannel.handle_info/2 score=50.22
  lib/realtime_web/dashboard/feature_flags.ex RealtimeWeb.Dashboard.FeatureFlags.handle_event/3 score=112.70
  lib/realtime_web/dashboard/node_info.ex RealtimeWeb.Dashboard.NodeInfo.fetch_node_data/2 score=42.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.handle_event/3 score=552.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.handle_info/2 score=210.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.render_value/2 score=42.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.load_module_functions/1 score=42.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.parse_and_start/2 score=110.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.format_value/1 score=552.00
  lib/realtime_web/dashboard/recon_trace.ex RealtimeWeb.Dashboard.ReconTrace.sort_entries/2 score=42.00
  lib/realtime_web/dashboard/sql_inspector.ex RealtimeWeb.Dashboard.SqlInspector.handle_event/3 score=72.00
  lib/realtime_web/dashboard/sql_inspector.ex RealtimeWeb.Dashboard.SqlInspector.execute_read_only/1 score=72.00
  lib/realtime_web/dashboard/sql_inspector.ex RealtimeWeb.Dashboard.SqlInspector.mask_sensitive_columns/1 score=42.00
  lib/realtime_web/dashboard/sql_inspector.ex RealtimeWeb.Dashboard.SqlInspector.compare_cells/2 score=42.00
  lib/realtime_web/dashboard/sql_inspector.ex RealtimeWeb.Dashboard.SqlInspector.format_cell/1 score=72.00
  lib/realtime_web/dashboard/tenant_migrations.ex RealtimeWeb.Dashboard.TenantMigrations.handle_info/2 score=156.00
  lib/realtime_web/live/components.ex RealtimeWeb.Components.input/1 score=90.00
  lib/realtime_web/live/inspector_live/conn_component.ex RealtimeWeb.InspectorLive.ConnComponent.handle_event/3 score=53.83
  lib/realtime_web/live/inspector_live/event_log_component.ex RealtimeWeb.InspectorLive.EventLogComponent.category_variant/1 score=35.00
  lib/realtime_web/live/inspector_live/event_log_component.ex RealtimeWeb.InspectorLive.EventLogComponent.event_label/1 score=51.43
  lib/realtime_web/live/inspector_live/index.ex RealtimeWeb.InspectorLive.Index.handle_event/3 score=30.84
  lib/realtime_web/live/status_live/index.ex RealtimeWeb.StatusLive.Index.handle_event/3 score=42.00

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 93.125% (+0.002%) from 93.123% — feat/readiness-min-nodes-per-region into main

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants