Interface AsyncStickyBucketService

All Known Implementing Classes:
SyncOffloadStickyBucketAdapter

public interface AsyncStickyBucketService
Non-blocking sticky bucket persistence for the multi-user GrowthBookClient: reads and writes never run on the evaluating thread's time. This is the async twin of StickyBucketService, mirroring the JavaScript SDK's Promise-based service interface and the Python SDK's AbstractAsyncStickyBucketService.

Implementations back this with a network store (Redis, DynamoDB, JDBC, ...) using their client's native async API. Methods return CompletionStage so natively-async clients (e.g. Lettuce's RedisFuture, Reactor's Mono#toFuture()) plug in without adaptation.

Contract:

  • Store keys use attributeName + "||" + attributeValue (getKey(java.lang.String, java.lang.String)), byte-compatible with documents written by the other GrowthBook SDKs against the same store.
  • getAssignments(java.lang.String, java.lang.String) completes with null when no document exists for the key.
  • Completion may happen on the store client's own threads (e.g. a Netty event loop) — the SDK hops off that thread before evaluating, and implementations should not block inside completion callbacks.
  • Implementations must be thread-safe; the SDK calls them concurrently.

Existing synchronous StickyBucketService implementations do not need porting — pass them as Options.stickyBucketService. The synchronous evaluation API calls them on the calling thread; the asynchronous entry points offload their blocking calls to the client's executor (see SyncOffloadStickyBucketAdapter), which costs a thread per in-flight call. Only an implementation of this interface on a natively asynchronous client avoids that.

  • Method Details

    • getAssignments

      CompletionStage<StickyAssignmentsDocument> getAssignments(String attributeName, String attributeValue)
      Look up one sticky bucket document.
      Parameters:
      attributeName - the identifier attribute name (e.g. id)
      attributeValue - the identifier attribute value
      Returns:
      a stage completing with the document, or null if absent
    • saveAssignments

      Persist one sticky bucket document (upsert by attributeName + "||" + attributeValue).
      Parameters:
      doc - the document to persist
      Returns:
      a stage completing when the write is durable
    • getKey

      default String getKey(String attributeName, String attributeValue)
      The store key for a document. Shared convention across all GrowthBook SDKs.
      Parameters:
      attributeName - the identifier attribute name
      attributeValue - the identifier attribute value
      Returns:
      attributeName + "||" + attributeValue
    • getAllAssignments

      default CompletionStage<Map<String,StickyAssignmentsDocument>> getAllAssignments(Map<String,String> attributes)
      Look up the documents for all of a user's identifier attributes.

      The default implementation fans out one getAssignments(java.lang.String, java.lang.String) call per attribute. Override it to batch all lookups into a single round trip (e.g. one Redis MGET) — this method is called once per sticky bucket fetch, so batching here is the highest-leverage optimization.

      Parameters:
      attributes - identifier attribute name → value
      Returns:
      a stage completing with found documents keyed by getKey(java.lang.String, java.lang.String); attributes with no document are omitted