Fast Client#
The Fast Client is Venice's high-performance read client that routes requests directly to servers (bypassing the Router), and provides lower latency than the Thin Client.
Characteristics#
- Partition-aware: Maintains metadata to route directly to the correct server
- Network hops: 1 (client → server)
- Typical latency: < 2ms
- Best for: Applications requiring low latency with moderate resource overhead
When to Use#
Choose the Fast Client when:
- You need lower latency than the Thin Client (< 2ms vs < 10ms)
- You can accept some additional memory overhead for metadata caching
- Your application makes frequent reads and benefits from direct server routing
- You want built-in long-tail retry and load control features
For the lowest latency, consider the Da Vinci Client (0 hops, < 1ms). For simplicity, consider the Thin Client.
Usage#
Dependency#
Add the Venice client dependency to your project:
Creating a Client#
Use ClientFactory from the fastclient package:
// Create R2 client for HTTP communication
HttpClientFactory httpClientFactory = new HttpClientFactory.Builder()
.setUsePipelineV2(true) // Enable HTTP/2
.build();
Client r2Client = new TransportClientAdapter(
httpClientFactory.getClient(Collections.emptyMap())
);
// Create D2 client for service discovery
D2Client d2Client = new D2ClientBuilder()
.setZkHosts("zookeeper.example.com:2181") // Your ZooKeeper hosts
.build();
D2ClientUtils.startClient(d2Client); // Start the D2 client
// Create Fast Client configuration
ClientConfig clientConfig = new ClientConfig.ClientConfigBuilder<>()
.setStoreName("my-store")
.setR2Client(r2Client)
.setD2Client(d2Client)
.setClusterDiscoveryD2Service("VeniceController")
.build();
// Create and start the Fast Client
AvroGenericStoreClient<String, MyValue> client =
ClientFactory.getAndStartGenericStoreClient(clientConfig);
With SSL, add SSL properties to the R2 and D2 clients:
// R2 client: Add SSL properties to httpClientFactory.getClient()
Map<String, Object> sslProperties = new HashMap<>();
sslProperties.put(HttpClientFactory.HTTP_SSL_CONTEXT, sslFactory.getSSLContext());
sslProperties.put(HttpClientFactory.HTTP_SSL_PARAMS, sslFactory.getSSLParameters());
Client r2Client = new TransportClientAdapter(
httpClientFactory.getClient(sslProperties) // Use sslProperties instead of Collections.emptyMap()
);
// D2 client: Add SSL configuration to builder
D2Client d2Client = new D2ClientBuilder()
.setZkHosts("zookeeper.example.com:2181")
.setIsSSLEnabled(true)
.setSSLContext(sslFactory.getSSLContext())
.setSSLParameters(sslFactory.getSSLParameters())
.build();
Reading Data#
The Fast Client implements the same AvroGenericStoreClient interface as the Thin Client:
Single Get#
// Asynchronous single-key lookup
CompletableFuture<MyValue> future = client.get("my-key");
MyValue value = future.get();
Batch Get#
Set<String> keys = Set.of("key1", "key2", "key3");
Map<String, MyValue> results = client.batchGet(keys).get();
Using Specific Records#
For type-safe access with Avro-generated classes:
ClientConfig clientConfig = new ClientConfig.ClientConfigBuilder<String, MyValueRecord, MyValueRecord>()
// ... basic config ...
.setSpecificValueClass(MyValueRecord.class)
.build();
AvroSpecificStoreClient<String, MyValueRecord> client =
ClientFactory.getAndStartSpecificStoreClient(clientConfig);
Key Features#
Long-Tail Retry#
Automatically retry slow requests to improve P99 latency:
ClientConfig clientConfig = new ClientConfig.ClientConfigBuilder<>()
// ... basic config ...
.setLongTailRetryEnabledForSingleGet(true)
.setLongTailRetryThresholdForSingleGetInMicroSeconds(5000) // 5ms
.setLongTailRetryEnabledForBatchGet(true)
.build();
Advanced Configuration#
Configure retry budget, load control, and dual-read mode:
ClientConfig clientConfig = new ClientConfig.ClientConfigBuilder<>()
// ... basic config ...
// Retry budget (enabled by default) - prevents retry storms
.setRetryBudgetEnabled(true)
.setRetryBudgetPercentage(0.1) // Allow 10% of requests to retry
// Load control - automatic request rejection when overloaded
.setStoreLoadControllerEnabled(true)
.setStoreLoadControllerMaxRejectionRatio(0.5) // Max 50% rejection
// Dual read - run alongside Thin Client for gradual migration
.setDualReadEnabled(true)
.setGenericThinClient(thinClient) // Your existing Thin Client instance
.build();
Dual-read metrics are registered in RRD (Tehuti) only when setDualReadEnabled(true) is configured. Store-load-controller metrics are registered and emitted in RRD and OpenTelemetry only when setStoreLoadControllerEnabled(true) is configured. Both features are disabled by default. These settings do not disable core request metrics, no-available-replica metrics, or aggregate instance-health metrics.
Application Execution Context#
Applications with thread-bound context can configure setExecutionContextProvider(ExecutionContextProvider). The provider captures the caller's context before asynchronous work and supplies a reusable snapshot that runs tasks synchronously under that context. Fast Client uses it for single-get and batch/compute retries, response deserialization, and future/streaming completion tasks, including requests that do not retry and optional dual-read completion when either the Fast Client or Thin Client finishes.
One snapshot is captured per logical request and shared by its routes and retry attempts. All records in one batch invocation use that request's originating context; separate invocations may have different contexts. Propagation is scoped to response/decoder tasks rather than individual records, so its scope count does not grow with the number of records in a response. Application callbacks must restore any context changes they make before returning.
The provider must restore each worker's previous context in a finally block, including on exceptions, and must not swallow exceptions or execute failed callbacks again. Snapshots must support concurrent use by the original request and its retry. The default provider runs tasks directly without capturing or changing context, and returns tasks and callbacks unchanged instead of decorating them, preserving existing behavior. Applications must supply their context implementation; no context framework is selected automatically.
Failures from scoped work are reported before the installed scope exits, without replaying callbacks. If installation or scope cleanup itself fails while the request is still pending, the affected operation reports the failure through its request completion rather than running work without context. That failure notification may run under the worker's previous context; a failure already reported from inside the scope is not reported again. A cleanup failure cannot replace an already-delivered result. With a configured provider, terminal streaming notification waits for record callbacks already in progress; records arriving after completion has been claimed are ignored.
The guarantee covers code that executes within the client's scoped tasks, including streaming callbacks and future continuations that actually run inline on the scoped completing thread. A plain CompletableFuture can also execute a pending synchronous continuation on another thread helping complete the future, such as a timed get() waiter, even when the continuation was registered before completion. Such execution is outside the client's scope. Applications remain responsible for propagating context to these continuations, to asynchronous continuation executors, and to callbacks attached after completion, which Java executes on the registering thread.
Configuration Options#
Key configuration options for ClientConfig:
| Option | Description | Default |
|---|---|---|
setStoreName(String) | Store name (required) | - |
setR2Client(Client) | R2 client for HTTP (required unless using gRPC) | - |
setD2Client(D2Client) | D2 client for service discovery | - |
setClusterDiscoveryD2Service(String) | D2 service name for controller | - |
setMetadataRefreshIntervalInSeconds(long) | Metadata refresh interval | 60 |
setLongTailRetryEnabledForSingleGet(boolean) | Enable retry for single get | false |
setLongTailRetryEnabledForBatchGet(boolean) | Enable retry for batch get | false |
setRetryBudgetEnabled(boolean) | Enable retry budget | true |
setRetryBudgetPercentage(double) | Max retry rate percentage (0.0-1.0) | 0.1 |
setStoreLoadControllerEnabled(boolean) | Enable load control | false |
setDisableRouteMetrics(boolean) | Disable per-backend-host metrics in RRD and OpenTelemetry | true |
Per-backend-host route metrics are disabled by default to limit metric cardinality. This includes route request counts, latencies, pending request counts, and rejection ratios for single-get, batch-get, and compute requests. Store-level request metrics and aggregate instance-health metrics remain enabled. Set setDisableRouteMetrics(false) to opt into route metrics for both RRD (Tehuti) and OpenTelemetry.
Routing Strategies#
Configure different routing strategies:
ClientConfig clientConfig = new ClientConfig.ClientConfigBuilder<>()
// ... basic config ...
.setClientRoutingStrategyType(ClientRoutingStrategyType.LEAST_LOADED)
.build();
Available strategies:
LEAST_LOADED: Route to the server with the least pending requestsHELIX_ASSISTED: Use Helix routing information
gRPC Support#
Enable gRPC transport for potentially lower latency:
GrpcClientConfig grpcConfig = new GrpcClientConfig.Builder()
.setR2Client(r2Client) // Required for non-storage requests
.setNettyServerToGrpcAddress(serverToGrpcMap)
.build();
ClientConfig clientConfig = new ClientConfig.ClientConfigBuilder<>()
// ... basic config ...
.setUseGrpc(true)
.setGrpcClientConfig(grpcConfig)
.build();
Health Monitoring#
Configure instance health monitoring to avoid unhealthy servers:
InstanceHealthMonitorConfig healthConfig = new InstanceHealthMonitorConfig.Builder()
.setClient(r2Client)
.setRoutingRequestDefaultTimeoutMS(1000)
.setRoutingPendingRequestCounterInstanceBlockThreshold(50)
.setHeartBeatIntervalSeconds(30)
.setHeartBeatRequestTimeoutMS(10000)
.build();
ClientConfig clientConfig = new ClientConfig.ClientConfigBuilder<>()
// ... basic config ...
.setInstanceHealthMonitor(new InstanceHealthMonitor(healthConfig))
.build();
Client Lifecycle#
Closing the Client#
Always close clients properly to release resources:
// Close the Venice client
client.close();
// Shutdown D2 client
D2ClientUtils.shutdownClient(d2Client);
// Shutdown R2 client
r2Client.shutdown(null);
Best Practices#
- Configure D2 properly: The Fast Client relies on D2 for metadata discovery
- Enable retry for critical paths: Long-tail retry improves P99 latency
- Use retry budget: Prevents retry storms under load
- Monitor health metrics: The Fast Client exposes metrics for monitoring
- Start with conservative settings: Tune retry thresholds based on observed latency
- Always close clients: Properly shutdown all clients to prevent resource leaks