pomerium/pkg/grpc/databroker
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
..
mock_databroker config: add support for http3 advertise port (#5466) 2025-02-03 13:58:57 -07:00
changeset.go databroker: preserve data type when deleting changeset (#5540) 2025-03-25 10:11:36 -06:00
changeset_test.go databroker: preserve data type when deleting changeset (#5540) 2025-03-25 10:11:36 -06:00
databroker.go proxy: use querier cache for user info (#5532) 2025-03-20 09:50:22 -06:00
databroker.pb.go databroker: add a wait field to sync request (#5630) 2025-05-29 12:50:14 -06:00
databroker.proto databroker: add a wait field to sync request (#5630) 2025-05-29 12:50:14 -06:00
databroker_grpc.pb.go core/proto: update protoc dependencies (#5218) 2024-08-15 11:12:05 -06:00
databroker_test.go chore(deps): bump the go group with 21 updates (#5162) 2024-07-05 13:26:47 -06:00
fast_forward.go logging: remove ctx from global log methods (#5337) 2024-10-23 14:18:52 -06:00
fast_forward_test.go
leaser.go logging: standardize on hyphens in attribute names (#5577) 2025-04-22 10:57:19 -07:00
leaser_test.go Fix many instances of contexts and loggers not being propagated (#5340) 2024-10-25 14:50:56 -04:00
reconciler.go Fix many instances of contexts and loggers not being propagated (#5340) 2024-10-25 14:50:56 -04:00
recordset.go reconciler: allow custom comparison function (#4726) 2023-11-08 20:11:49 -05:00
recordset_test.go reconciler: allow custom comparison function (#4726) 2023-11-08 20:11:49 -05:00
sync.go core/zero: add usage reporter (#5281) 2024-09-12 15:45:54 -06:00
sync_cache.go databroker: add sync-cache (#5639) 2025-06-02 13:42:30 -06:00
sync_cache_test.go databroker: add sync-cache (#5639) 2025-06-02 13:42:30 -06:00
sync_test.go New tracing system (#5388) 2025-01-21 13:26:32 -05:00
syncer.go logging: standardize on hyphens in attribute names (#5577) 2025-04-22 10:57:19 -07:00
syncer_test.go Fix many instances of contexts and loggers not being propagated (#5340) 2024-10-25 14:50:56 -04:00