Skip to content

Async Kotlin client in Java SDK #67683

Open

Description

@uranusjr

Java doesn’t do coroutines, so the current Client implementation is sync. But Kotlin does, and we might benefit from a different async client. I think we can do it like this:

  1. Add an AsyncTask protocol that has an suspend fun execute instead of the sync execute function.
  2. Create an AsyncClient class to use instead of Client. suspend fun execute(client: AsyncClient, context: Context).
  3. When the task is executed, check which protocol is used. Wrap runBlocking around the async task.
  4. Make the annotation processor detect suspend fun so the same @Builder.Task can be used on both sync and async and automatically does the right thing.

The only question is whether we just add Async to both Task and Client. Should the sync version be renamed? (BlockingTask & BlockingClient?)

Activity

  1. added theissue type on May 29, 2026
  2. added
    kind:feature
    on May 29, 2026
  3. subramanya-dev commented on May 29, 2026

    @subramanya-dev

    @uranusjr I’d be happy to work on this feature, please assign it to me if available.

  4. potiuk commented on May 30, 2026

    @potiuk
    Member

    We do not assign issues - see contributing guide. But feel free to work on it.

  5. added this to the Airflow 3.4.0 milestone on Jun 9, 2026
  6. uranusjr commented on Jun 13, 2026

    @uranusjr
    MemberAuthor

    I thought about this a bit. Since it doesn’t really make much sense to expose this to Java (any language except Kotlin really), it’s probably better to split this into a separate package, or even a separate artifact. Not sure. Probably better than to prefix everything (AsyncClient AsyncTask and so on. I’m not exactly sure what the best approach here is tbh.)

    Either way, we should

    1. Create an async equivalent of org.apache.airflow.sdk.execution.Client.
    2. Create an async equivalent of org.apache.airflow.sdk.Client.
    3. Create an async Task interface that requires suspend fun execute(Context, Client) where Client is the async version (Context should be the same).
    4. Extend Dag.add_task() to also accept an async Task, and TaskRunner to handle it.
    5. Extend @Builder.Task to be able to convert an annotated suspend fun to an async Task.
  7. moved this from Backlog to In progress in Java-SDKon Jul 17, 2026
  8. shaealh commented on Jul 21, 2026

    @shaealh
    Contributor

    @uranusjr I opened PR - please review when you get a chance, thanks

  9. jason810496 commented on Jul 31, 2026

    @jason810496
    Member

    I think it's reasonable to leave this out for now.

    Actually, I meant to support "multiplexing" in the Java-SDK execution path, rather than a suspend-based API, since suspend is Kotlin-specific in our previous offline discussion.

    As Java SDK: Change coordinator comm to use multiplexing #69254 merged, the runtime won't serialized each request and response. There is also an e2e test to exercise the concurrent example:

    https://github.com/apache/airflow/blob/e3ea8b29859b6a13f32e8f26d0fae433e58cc3af/java-sdk/example/src/java/org/apache/airflow/example/AnnotationExample.java#L79-L99

    Threads and virtual threads are the more common concurrency model in the JVM, Anyway, we can reopen this if the suspend API turns out to be necessary.

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

    Projects

    • Status
      In progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions