Skip to content
Leader docs0.4

Exposed R2DBC backend

Latest stable Based on Leader release 0.4.0

Library module

Implements coroutine single and group election with Exposed R2DBC transactions while sharing SQL ownership rules with JDBC.

Choose it for coroutine-first R2DBC services; choose JDBC when surrounding APIs are blocking or virtual-thread based.

Artifact: io.github.bluetape4k.leader:bluetape4k-leader-exposed-r2dbc

dependencies {
implementation(platform("io.github.bluetape4k:bluetape4k-dependencies:<version>"))
implementation("io.github.bluetape4k.leader:bluetape4k-leader-exposed-r2dbc")
}

Suspend transactions perform conditional writes with expiry and owner tokens. Cancellation must clean up only the lease owned by that call.

val elector = ExposedR2DbcSuspendLeaderElector(database)
elector.runIfLeader("projection-refresh") { refreshProjection() }

Use suspend single/group electors, R2dbcDatabase extensions, factories, initializer, and suspend history sink.

Keep acquire/use/release in structured scope, do not hide JDBC blocking calls inside it, and migrate the shared schema first.

Can share a namespace with JDBC when database, schema, and release match. Spring and Ktor consume the suspend factory/elector.

Tune wait, lease, retry, schema, R2DBC pool, statement timeout, and lifecycle ownership.

Contention returns null; cancellation rethrows after owner-safe cleanup; connection and transaction failures propagate.

Observe acquisition latency, pool queue time, retries, cancellation cleanup, and database load.

Use a real R2DBC database for two-client contention, group slots, expiry, and cancellation during acquire/action.

Compare JDBC, then run migration-gate and the Ktor example to see lifecycle integration.

R2DBC removes blocked threads, not database round trips or database availability risk.

These diagrams are loaded directly from README assets published with the 0.4.0 release and pinned to its immutable commit. They describe this manual’s released structure and runtime flows, not later Snapshot changes. Select a preview to open the SVG at the same release commit.

leader exposed r2dbc Class Structure diagram

Section titled “leader exposed r2dbc Class Structure diagram”

leader exposed r2dbc Class Structure diagram

Release README: leader-exposed-r2dbc/README.md

Elector · Initializer · Stable guide