pomerium/pkg/grpc
Caleb Doxsey ff607fa018
databroker: add sync-cache (#5639)
## Summary
Add a new `SyncCache`:

```go
type SyncCache interface {
	// Clear deletes all the data for the given record type in the sync cache.
	Clear(recordType string) error
	// Records yields the databroker records stored in the cache.
	Records(recordType string) iter.Seq2[*Record, error]
	// Sync syncs the cache with the databroker.
	Sync(ctx context.Context, client DataBrokerServiceClient, recordType string) error
}
```

The cache maintains databroker records in a local pebble database (which
could be on-disk or in-memory). The way it's used is you first call
`.Sync(ctx, client, recordType)` and then `.Records(recordType)`, which
returns an iterator over all the records.

Internally we store the databroker records in a pebble key-value
database. Pebble was chosen because its fast and well-tested, but any
ordered key-value store would work. The first time we call `SyncLatest`
to retrieve all the records. Each subsequent time we call `Sync` with
the current server and record versions to retrieve only the changes.
This is significantly more efficient than calling `SyncLatest` every
time.

The primary use for this is in the enterprise-console as part of
directory sync to improve performance with large datasets.

## Related issues
-
[ENG-2401](https://linear.app/pomerium/issue/ENG-2401/enterprise-console-improve-performance-of-directory-sync-using-cached)

## Checklist

- [x] reference any related issues
- [x] updated unit tests
- [x] add appropriate label (`enhancement`, `bug`, `breaking`,
`dependencies`, `ci`)
- [x] ready for review

---------

Co-authored-by: Denis Mishin <dmishin@pomerium.com>
2025-06-02 13:42:30 -06:00
..
audit core/proto: update protoc dependencies (#5218) 2024-08-15 11:12:05 -06:00
cli core/proto: update protoc dependencies (#5218) 2024-08-15 11:12:05 -06:00
config mcp: pass access token to the upstream (#5593) 2025-04-29 12:13:18 -04:00
databroker databroker: add sync-cache (#5639) 2025-06-02 13:42:30 -06:00
device core/proto: update protoc dependencies (#5218) 2024-08-15 11:12:05 -06:00
events core/proto: update protoc dependencies (#5218) 2024-08-15 11:12:05 -06:00
identity authorize: support authenticating with idp tokens (#5484) 2025-02-18 13:02:06 -07:00
registry config: add support for http3 advertise port (#5466) 2025-02-03 13:58:57 -07:00
session upgrade to go v1.24 (#5562) 2025-04-02 15:53:09 -06:00
testdata grpc: rename internal/grpc to pkg/grpc (#1010) 2020-06-26 09:17:02 -06:00
user upgrade to go v1.24 (#5562) 2025-04-02 15:53:09 -06:00
client.go New tracing system (#5388) 2025-01-21 13:26:32 -05:00
docs.go grpc: rename internal/grpc to pkg/grpc (#1010) 2020-06-26 09:17:02 -06:00
health.go upgrade google.golang.org/grpc/health/grpc_health_v1 (#5605) 2025-05-02 14:32:04 -06:00
protoc.bash authorize/log: remove audit logging (#5369) 2024-11-22 14:32:52 -05:00