Skip to main content
This SDK supports Kotlin and Java backend applications running on the JVM, including server applications, CLI tools, and worker processes. It’s optimized for server-side usage with suspend-first APIs and production-safe defaults.
Android Development?If you’re building Android applications, see the Kotlin (Android) documentation instead, which includes Android-specific guidance for Gradle Android plugin, Android engines, and AARs.

Supported Platforms

  • JVM: Java 8+ and Kotlin 1.5+
  • Server Applications: Ktor, Spring Boot, Micronaut, Quarkus
  • CLI Tools: Command-line applications and scripts
  • Worker Processes: Background jobs and data processing
  • Microservices: Containerized applications and serverless functions

Installation

Add the GrowthBook JVM SDK and a network dispatcher to your project:
Important: Use JVM-specific ArtifactsAlways use the -jvm variants of the artifacts for server applications. Do not include Android artifacts or the Ktor Android engine, as they will add unnecessary dependencies and increase your application size.

Quick Start

Here’s a minimal example to get started with the GrowthBook Kotlin JVM SDK:

Network Dispatchers

The GrowthBook SDK requires a network dispatcher for fetching feature definitions. Choose the appropriate one for your use case: Best for most server applications due to its smaller dependency footprint:

Ktor CIO Dispatcher

Use this if you’re already using Ktor in your application:
Avoid Android EnginesWhen using Ktor, always specify the CIO engine explicitly. Do not use the Android engine in server applications as it will add unnecessary dependencies.

Configuration

Configure the GrowthBook SDK for your server environment:

Evaluating Features and Running Experiments

Feature Flags

Evaluate feature flags to control application behavior:

Feature Evaluation with Context

Update user attributes for different contexts:

Running Experiments

Run A/B tests and experiments directly:

Experiment Tracking

Track experiment exposures for analytics:

Advanced Features

For more advanced usage including sticky bucketing, encrypted features, custom attributes, and mobile-specific considerations, see the Kotlin (Android) documentation which covers these topics in detail.

Serialization Support

The optional serialization module provides helpers for working with GBValue and kotlinx.serialization:
When to Use SerializationYou only need the serialization module if you want to work with complex JSON feature values as typed Kotlin objects. For simple boolean, string, and number features, you can skip this dependency.

Caching and Server-Sent Events

Caching

The builder exposes a cachingEnabled flag. On JVM, fetched features remain in the SDK instance after refresh, but there is no platform-provided persistent local cache layer:
To be notified when features are refreshed, use setRefreshHandler() on the builder:

Real-time Updates with SSE

Start a persistent Server-Sent Events connection for live feature updates:

Error Handling and Observability

Exception Handling

The SDK uses suspend functions and handles errors gracefully:

Logging Integration

The SDK outputs debug information to stdout when enableLogging is set to true. You can capture this in your application by redirecting stdout to your logging framework:

Testing

Mock Dispatchers

Use mock dispatchers for unit testing:

Deterministic Testing

Use local JSON fixtures for predictable tests:

Performance and Resource Usage

Connection Pooling

Configure connection pooling for high-throughput applications:

Coroutine Dispatchers

Use appropriate dispatchers for different workloads:

Avoid Blocking Calls

Never use runBlocking on request threads in server applications:

Framework Integration Examples

Ktor Server

Spring Boot

CLI Application

Versioning and Compatibility

Module Versions

GrowthBook Kotlin JVM modules follow independent versioning:

Compatibility Matrix

Dependency Management

Pin JVM-specific versions explicitly in monorepos:

Migration from Android Documentation

If you started with the Android documentation but need server-side usage:

Key Differences

Migration Steps

  1. Update Dependencies: Replace Android artifacts with JVM variants
  2. Remove Android Engines: Use OkHttp or Ktor CIO only
  3. Update Network Dispatcher: Ensure JVM-compatible engines
  4. Review Threading: Remove runBlocking from request handlers
  5. Update Caching: Configure appropriate TTL for server usage

Troubleshooting

Common Issues

Problem: ClassNotFoundException for Android classes
Problem: Large JAR size in server deployments
Problem: Blocking network calls in request handlers
Problem: Features not updating in long-running processes

Debug Logging

Enable debug logging to troubleshoot issues. The SDK prints to stdout when enableLogging = true:

Supported Features

Further Reading


Need help? Join our Slack community or check out our GitHub repository for examples and support.