Skip to content

Implement async batch flush with background thread and Mutex #6

Description

@isaka1022

What

Buffer ingestion events in memory and flush them to the Langfuse endpoint in a background thread, using Mutex for thread-safe queue access. Provide a flush method and an at-exit hook for graceful shutdown.

Why

The current implementation fires an HTTP request synchronously on every create or update call, blocking the calling thread and adding latency to instrumented code. Production use cases (high-throughput Rails apps, batch pipelines) require non-blocking, batched I/O. The competing langfuse-ruby (ai-firstly) gem already ships async flush.

Effort estimate

M (2–3 days) — implement a thread-safe event queue, a background flush loop, configurable batch size and flush interval, and at-exit drain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    nextMedium priorityroadmapPlanned roadmap item

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions