{"id":51201153,"url":"https://github.com/shuakami/balancer","last_synced_at":"2026-06-28T00:30:48.180Z","repository":{"id":342203805,"uuid":"1173237202","full_name":"shuakami/balancer","owner":"shuakami","description":"Vercel Edge/Node compatible load balancer (P2C + PeakEWMA + circuit breaker).","archived":false,"fork":false,"pushed_at":"2026-03-05T06:37:32.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-05T11:36:11.953Z","etag":null,"topics":["ai","edge","ewma","load-balancer","p2c","serverless","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@sdjz/balacer","language":"TypeScript","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/shuakami.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-03-05T06:32:36.000Z","updated_at":"2026-03-05T06:58:21.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/shuakami/balancer","commit_stats":null,"previous_names":["shuakami/balancer"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/shuakami/balancer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuakami%2Fbalancer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuakami%2Fbalancer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuakami%2Fbalancer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuakami%2Fbalancer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shuakami","download_url":"https://codeload.github.com/shuakami/balancer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuakami%2Fbalancer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34873663,"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-27T02:00:06.362Z","response_time":126,"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":["ai","edge","ewma","load-balancer","p2c","serverless","typescript"],"created_at":"2026-06-28T00:30:48.102Z","updated_at":"2026-06-28T00:30:48.173Z","avatar_url":"https://github.com/shuakami.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @sdjz/balacer\n\nA **Vercel Edge / Vercel Serverless / Node 18+** compatible load balancer library.\n\nCore strategy:\n\n- **P2C (Power of Two Choices)**: O(1) selection with near-optimal distribution quality.\n- **Peak EWMA** latency: reacts quickly to tail latency spikes.\n- **inflight (least-loaded)**: avoids pushing traffic to already-queued instances.\n- **Error EWMA + Circuit Breaker**: penalize unhealthy instances and open circuits with exponential backoff.\n- **Soft stickiness (Jump Consistent Hash)**: session affinity that still escapes slow/unhealthy nodes.\n\n## Install\n\n```bash\nnpm i @sdjz/balacer\n```\n\n## Usage (HTTP / fetch)\n\n```ts\nimport { LoadBalancer } from '@sdjz/balacer';\n\nconst balancer = new LoadBalancer([\n  { id: 'a', url: 'https://a.example.com', weight: 2, maxInflight: 64, pools: ['chat'] },\n  { id: 'b', url: 'https://b.example.com', weight: 1, maxInflight: 32, pools: ['chat'] },\n]);\n\nexport default async function handler(req: Request): Promise\u003cResponse\u003e {\n  const userId = req.headers.get('x-user-id') ?? 'anon';\n  const body = await req.text();\n\n  return balancer.fetch(\n    { key: userId, pool: 'chat' },\n    '/v1/infer',\n    { method: 'POST', headers: { 'content-type': 'application/json' }, body },\n    { timeoutMs: 20_000, retries: 1, hedgeAfterMs: 400 }\n  );\n}\n```\n\n## Usage (custom task)\n\n```ts\nconst out = await balancer.run(\n  { key: 'user-123' },\n  async (backend, { signal }) =\u003e {\n    return myRpcCall(backend.meta?.endpoint as string, { signal });\n  },\n  { maxAttempts: 2, timeoutMs: 10_000 }\n);\n```\n\n## Build\n\n```bash\nnpm run build\n```\n\n## Test\n\n```bash\nnpm test\n```\n\nMIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuakami%2Fbalancer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshuakami%2Fbalancer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuakami%2Fbalancer/lists"}