{"id":50873182,"url":"https://github.com/cktan/swim-ex","last_synced_at":"2026-06-15T07:04:22.137Z","repository":{"id":361802209,"uuid":"1255784101","full_name":"cktan/swim-ex","owner":"cktan","description":"SWIM gossip membership for Elixir over pure UDP — no epmd, no Erlang distribution required","archived":false,"fork":false,"pushed_at":"2026-06-07T12:39:12.000Z","size":203,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-11T05:06:21.844Z","etag":null,"topics":["beam","cluster","distributed-systems","elixir","failure-detection","gossip-protocol","membership","otp","swim-protocol","udp"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cktan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-01T07:02:29.000Z","updated_at":"2026-06-07T12:39:15.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/cktan/swim-ex","commit_stats":null,"previous_names":["cktan/swim-ex"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cktan/swim-ex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Fswim-ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Fswim-ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Fswim-ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Fswim-ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cktan","download_url":"https://codeload.github.com/cktan/swim-ex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Fswim-ex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34351452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beam","cluster","distributed-systems","elixir","failure-detection","gossip-protocol","membership","otp","swim-protocol","udp"],"created_at":"2026-06-15T07:04:19.093Z","updated_at":"2026-06-15T07:04:22.128Z","avatar_url":"https://github.com/cktan.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swim_ex\n\nA SWIM+INF+Susp cluster membership library for Elixir.\n\nNodes in a cluster automatically discover each other,\ndetect failures, and converge on a shared view of\nmembership — all over UDP, with no central coordinator.\n\n```elixir\nchildren = [\n  {SwimEx.Supervisor,\n   host: \"10.0.0.1\",\n   port: 7771,\n   seeds: [{\"10.0.0.2\", 7771}, {\"10.0.0.3\", 7771}]}\n]\n\nSwimEx.subscribe()\n# receives {:swim, :node_up, {\"10.0.0.2\", 7771, \"c1\"}} etc.\n\nSwimEx.members()\n#=\u003e [{\"10.0.0.2\", 7771, \"c1\", :alive, 3}, {\"10.0.0.3\", 7771, \"c1\", :suspect, 1}]\n```\n\n\n---\n\n## What is SWIM?\n\nSWIM (Scalable Weakly-consistent Infection-style\nMembership) is a gossip protocol from a 2002 Cornell\npaper. Each node periodically pings one other node. If\nthe ping fails, it asks a few random nodes to relay an\nindirect ping. Only if both fail does the target become\nsuspect. After a suspicion timeout it is declared dead.\n\nThis library implements the SWIM+INF+Susp variant, which\nadds:\n\n- **Incarnation numbers** — each node carries a\n  monotonically increasing counter. A suspected node\n  can refute false positives by broadcasting an alive\n  event with a higher incarnation number.\n- **Suspicion period** — a configurable delay between\n  first suspecting a node and declaring it dead,\n  reducing false positives from GC pauses or\n  transient packet loss.\n\n---\n\n## Tradeoffs\n\n### SWIM, not Raft or Paxos\n\nswim_ex detects membership changes; it does not provide\nconsensus, leader election, or reliable delivery. If you\nneed those, layer them on top with a library such as\nRa. swim_ex's value is low overhead: O(1) messages per\nnode per period regardless of cluster size.\n\n### ETF wire format\n\nMessages are encoded with `:erlang.term_to_binary/1`.\nThis is trivially fast in Elixir and requires zero\ndependencies, but it means non-BEAM nodes cannot\nparticipate. If polyglot clusters matter, the codec\nmodule is the only place that needs to change.\n\n### UDP, no reliability layer\n\nSWIM is designed for UDP. Occasional dropped messages\nare tolerable — the protocol's redundant gossip and\nrepeated pinging absorb them. Adding TCP would reduce\nfalse positives in pathological networks but defeats\nmuch of SWIM's simplicity. The tradeoff is documented;\nLifeguard extensions (Hashicorp's local health\nmultiplier) were deliberately excluded to keep the\nimplementation small.\n\n### Stable identity, time-seeded incarnation\n\nA node's identity is its `{host, port, cookie}` tuple, stable\nacross restarts. On each startup, the incarnation\nnumber is seeded from `System.system_time(:millisecond)`\nso a restarted node can always override stale dead\nevents from its previous life — without needing a\npersistent incarnation counter on disk. The caveat:\na large NTP step-back in the window between crash and\nrestart can delay re-joining. See DESIGN.md §9 for the\nfull analysis.\n\n### Pure functional core\n\nThe membership state machine (`SwimEx.Membership`) and\ngossip queue (`SwimEx.GossipQueue`) are pure functions\nover immutable structs. `SwimEx.Protocol` is a thin\nGenServer shell that owns timers and sockets and\ndelegates all state transitions to those modules. This\nseparation makes the protocol logic testable without\nstarting any processes, and makes the StreamData\nproperty tests possible.\n\n### In-memory transport for tests\n\nThe production transport is UDP only. An\n`SwimEx.Transport.InMemory` implementation lives in\n`test/support/` and is not part of the public API. It\nlets integration tests inject packet loss, delay, and\nreorder without any real sockets. A shared\n`Network` process acts as the routing hub between\nin-memory nodes.\n\n---\n\n## Status\n\nEarly release. The protocol implementation is complete\nand tested, but the library has not been run in\nproduction. Bug reports and pull requests welcome.\n\n**Tested on:** Elixir 1.15 / OTP 26.\n\n---\n\n## Documentation\n\n- **USAGE.md** — installation, configuration\n  reference, API, telemetry, and testing guide\n- **DESIGN.md** — full design decisions and\n  rationale, including every tradeoff answered before\n  the first line of code was written\n\n---\n\n## License\n\nMIT. See [LICENSE](https://github.com/cktan/swim-ex/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcktan%2Fswim-ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcktan%2Fswim-ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcktan%2Fswim-ex/lists"}