Skip to content

[Enhancement] Add virtual thread support for concurrent streaming sessions (Java 21+) #113

Description

@deepgram-robot

Summary

Add support for Java 21+ virtual threads (Project Loom) in the streaming STT and Voice Agent WebSocket clients, enabling efficient handling of hundreds of concurrent audio streams without thread pool exhaustion.

Problem it solves

Java developers building voice applications at scale — contact centers, meeting platforms, telephony systems — need to handle many concurrent streaming STT sessions simultaneously. The current SDK uses platform threads for WebSocket I/O, which limits practical concurrency to the thread pool size (typically 200-500 threads). With virtual threads, developers can run thousands of concurrent streaming sessions with minimal memory overhead, making Deepgram a natural fit for high-throughput Java applications.

Virtual threads are now widely adopted in Java 21+ (LTS) and supported by Spring Boot 3.2+, Quarkus 3.6+, and Micronaut 4.2+. Adding virtual thread support positions the Java SDK for modern Java deployments.

Proposed API

import com.deepgram.sdk.DeepgramClient;
import com.deepgram.sdk.listen.LiveOptions;

// Option 1: Explicit virtual thread executor
var client = DeepgramClient.builder()
    .apiKey(System.getenv("DEEPGRAM_API_KEY"))
    .useVirtualThreads(true)  // Uses virtual thread executor for WS I/O
    .build();

// Option 2: Custom executor (for frameworks that manage their own)
var client = DeepgramClient.builder()
    .apiKey(System.getenv("DEEPGRAM_API_KEY"))
    .executor(Executors.newVirtualThreadPerTaskExecutor())
    .build();

// Concurrent streaming — each session runs on a virtual thread
var sessions = audioFiles.stream()
    .map(file -> client.listen().live(options, new LiveHandler() {
        @Override
        public void onTranscript(LiveResult result) {
            // Process transcript
        }
    }))
    .toList();

Acceptance criteria

  • WebSocket clients support virtual thread executors when running on Java 21+
  • Graceful fallback to platform threads on Java 17 (compile-time compatible)
  • Configurable via builder pattern (useVirtualThreads() or custom Executor)
  • Tested with 100+ concurrent streaming sessions to validate scalability
  • Documented with usage example showing concurrent transcription
  • Compatible with existing API — no breaking changes for Java 17 users

Raised by the DX intelligence system.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions