{"id":19382734,"url":"https://github.com/authzed/crdbpool","last_synced_at":"2025-04-23T20:32:27.637Z","repository":{"id":176688030,"uuid":"644692992","full_name":"authzed/crdbpool","owner":"authzed","description":"node aware connection pooling for CockroachDB","archived":false,"fork":false,"pushed_at":"2023-06-07T14:45:52.000Z","size":78,"stargazers_count":24,"open_issues_count":2,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-20T10:04:58.178Z","etag":null,"topics":["cockroachdb","connection-pool","pgx","spicedb"],"latest_commit_sha":null,"homepage":"https://authzed.com/blog/maximizing-cockroachdb-performance","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/authzed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","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}},"created_at":"2023-05-24T04:05:04.000Z","updated_at":"2024-12-15T01:10:59.000Z","dependencies_parsed_at":"2023-07-26T01:32:52.335Z","dependency_job_id":null,"html_url":"https://github.com/authzed/crdbpool","commit_stats":null,"previous_names":["authzed/crdbpool"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/authzed%2Fcrdbpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/authzed%2Fcrdbpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/authzed%2Fcrdbpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/authzed%2Fcrdbpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/authzed","download_url":"https://codeload.github.com/authzed/crdbpool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250509856,"owners_count":21442509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cockroachdb","connection-pool","pgx","spicedb"],"created_at":"2024-11-10T09:23:02.344Z","updated_at":"2025-04-23T20:32:27.628Z","avatar_url":"https://github.com/authzed.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crdbpool\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/authzed/crdbpool)](https://goreportcard.com/report/github.com/authzed/crdbpool)\n[![GoDoc](https://pkg.go.dev/badge/s.svg)](https://pkg.go.dev/github.com/authzed/crdbpool)\n\n`crdbpool` implements a node-aware connection pool for [CockroachDB] by wrapping [pgx].\n\nBy introducing advanced health-checking, this library is able to improve:\n\n- performance by balancing connections evenly across nodes\n- resiliency by retrying failed queries against a different node\n\nHave questions? Ask in our [Discord].\n\nLooking to contribute? See [CONTRIBUTING.md].\n\nYou can find issues by priority: [Urgent], [High], [Medium], [Low], [Maybe].\nThere are also [good first issues].\n\n[CockroachDB]: https://github.com/cockroachdb/cockroach\n[pgx]: https://github.com/jackc/pgx\n[Discord]: https://authzed.com/discord\n[CONTRIBUTING.md]: https://github.com/authzed/spicedb/blob/main/CONTRIBUTING.md\n[Urgent]: https://github.com/authzed/spicedb/labels/priority%2F0%20urgent\n[High]: https://github.com/authzed/spicedb/labels/priority%2F1%20high\n[Medium]: https://github.com/authzed/spicedb/labels/priority%2F2%20medium\n[Low]: https://github.com/authzed/spicedb/labels/priority%2F3%20low\n[Maybe]: https://github.com/authzed/spicedb/labels/priority%2F4%20maybe\n[good first issues]: https://github.com/authzed/spicedb/labels/hint%2Fgood%20first%20issue\n\n## Example Usage\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/authzed/crdbpool\"\n\t\"github.com/jackc/pgx/v5\"\n\t\"github.com/jackc/pgx/v5/pgxpool\"\n\t\"golang.org/x/sync/errgroup\"\n)\n\nfunc main() {\n\t// Allocate a health checker that will track CockroachDB nodes\n\thealthChecker, err := crdbpool.NewNodeHealthChecker(\"postgres://username:password@localhost:5432/database_name\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Configure pgxpool as you normally would\n\tconfig, err := pgxpool.ParseConfig(\"postgres://username:password@localhost:5432/database_name\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Wrap the pgxpool with node-aware retry logic\n\tmaxRetries := 10\n\tconnectRate := 100 * time.Millisecond\n\tpool, err := crdbpool.NewRetryPool(context.TODO(), \"pool\", config, healthChecker, maxRetries, connectRate)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tctx, cancel := context.WithCancel(context.TODO())\n\tdefer cancel()\n\n\t// Start balancing connections and discovering nodes\n\tg, ctx := errgroup.WithContext(ctx)\n\tbalancer := pool.NewNodeConnectionBalancer(pool, healthChecker, 5*time.Second)\n\tg.Go(func() error {\n\t\tbalancer.Prune(ctx)\n\t\treturn nil\n\t})\n\tg.Go(func() error {\n\t\thealthChecker.Poll(ctx, 5*time.Second)\n\t\treturn nil\n\t})\n\n\t// Use the pgxpool as normal.\n\tpool.QueryFunc(ctx, func(ctx context.Context, rows pgx.Rows) error {\n\t\tdocs := make([][]byte, 0)\n\t\tfor rows.Next() {\n\t\t\tvar doc []byte\n\t\t\terr = rows.Scan(\u0026doc)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"couldn't scan document\")\n\t\t\t}\n\t\t\tdocs = append(docs, doc)\n\t\t}\n\t\treturn rows.Err()\n\t}, \"SELECT * FROM documents;\")\n}\n```\n\n## Acknowledgements\n\nThis library was produced from [AuthZed]'s findings along with the collaboration of [Cockroach Labs].\nAs a result, we'd like to thank a few notable contributors:\n\n- [Evan Cordell](https://github.com/ecordell)\n- [Bram Gruneir](https://github.com/BramGruneir)\n- Steven Hand\n\n[AuthZed]: https://authzed.com\n[Cockroach Labs]: https://cockroachdb.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauthzed%2Fcrdbpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauthzed%2Fcrdbpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauthzed%2Fcrdbpool/lists"}