# Query Batching in Android Client

**URL:** https://community.apollographql.com/t/query-batching-in-android-client/4622
**Category:** Client SDKs
**Tags:** kotlin, client, mobile
**Created:** [September 28, 2022, 8:25am UTC](https://community.apollographql.com/t/query-batching-in-android-client/4622 "2022-09-28T08:25:23Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ashuspeed](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/ashuspeed/32/2422_2.png) [@ashuspeed](https://community.apollographql.com/u/ashuspeed)
#### Post date: [September 28, 2022, 8:25am UTC](https://community.apollographql.com/t/query-batching-in-android-client/4622/1 "2022-09-28T08:25:23Z")

</div>

Team,  
i am using the Apollo android Client and wanted to explore the Batching Functionality, i explored the API but wanted to know the logical correctness of the code for Batched Execution of Queries.

Should we execute the queries one after another within the **startBatchPoller()** and **stopBatchPoller()** method?

```auto
BatchConfig batchConfig = new BatchConfig(true,10,15);
ApolloClient apolloClient = ApolloClient.builder()
                .serverUrl(graphQLServerURL)
                .okHttpClient(new OkHttpClient.Builder().addInterceptor(new AuthorizationInterceptor()).build())
                .batchingConfiguration(batchConfig)
                .build();

        apolloClient.startBatchPoller();
        apolloclient.enqueue(query1);
        apolloclient.enqueue(query2);
        apolloclient.enqueue(query3);
        apolloClient.stopBatchPoller();

```

or if there are any other ways please do let me know, how to run Queries in Batch Operation?

Thanks in Advance!!  
Appreciate your help.

---

<div class="post-metadata">

### Author: ![Benoit\_Lubek](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/benoit_lubek/32/2070_2.png) [@Benoit\_Lubek](https://community.apollographql.com/u/Benoit_Lubek)
#### Post date: [September 28, 2022, 11:59am UTC](https://community.apollographql.com/t/query-batching-in-android-client/4622/2 "2022-09-28T11:59:49Z")

</div>

Hi! 👋

Yes that’s how you would use it, except you will need to explicitly opt-in for batching on individual queries, with `.canBeBatched(true)`.

Also the call `stopBatchPoller` can be done later, when disposing of your `apolloClient`.

You can have a look at a unit test showcasing this [here](https://github.com/apollographql/apollo-kotlin/blob/92aa7b56b1bb268e95fdf93811dc61821d090bd6/apollo-integration/src/test/java/com/apollographql/apollo/internal/batch/BatchHttpResponseTest.kt#L27) (in Kotlin but equivalent Java code should be fairly equivalent).

---

<div class="post-metadata">

### Author: ![ashuspeed](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/ashuspeed/32/2422_2.png) [@ashuspeed](https://community.apollographql.com/u/ashuspeed)
#### Post date: [September 29, 2022, 12:01pm UTC](https://community.apollographql.com/t/query-batching-in-android-client/4622/3 "2022-09-29T12:01:42Z")

</div>

Hi @Benoit_Lubek , is Batching part of Version 3 library? I am using 2.5.11 version of Apollo Libraries.

---

<div class="post-metadata">

### Author: ![Benoit\_Lubek](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/benoit_lubek/32/2070_2.png) [@Benoit\_Lubek](https://community.apollographql.com/u/Benoit_Lubek)
#### Post date: [September 29, 2022, 1:03pm UTC](https://community.apollographql.com/t/query-batching-in-android-client/4622/4 "2022-09-29T13:03:45Z")

</div>

Yes, batching is also available in v3. Its usage is a bit different, but similar - you can have a look at the doc for it [here](https://www.apollographql.com/docs/kotlin/advanced/query-batching).

---

<div class="post-metadata">

### Author: ![ashuspeed](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/ashuspeed/32/2422_2.png) [@ashuspeed](https://community.apollographql.com/u/ashuspeed)
#### Post date: [January 25, 2023, 6:51pm UTC](https://community.apollographql.com/t/query-batching-in-android-client/4622/5 "2023-01-25T18:51:26Z")

</div>

Hi 👋  
I am able to use the batching functionality, however i wanted to understand few things to explore further and wanted to know with respect to Batching functionality in Android Client.

- Is Batching Supported only in Asynchronous Query Calls only? or can we use it in a Synchronous way using RX java?

- Just by looking at the responses received in the Asynchronous Batching call? Is there a way to find out which calls went as a single Batch Request?

- Any document or design doc/pointers to explore the functionality further like the configuration settings that can be tweaked to get optimized results in Android like we have the following [doc](https://www.apollographql.com/docs/react/api/link/apollo-link-batch-http/) for React

Any pointers will be highly appreciated.

Thanks in Advance!!

---

<div class="post-metadata">

### Author: ![Benoit\_Lubek](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/benoit_lubek/32/2070_2.png) [@Benoit\_Lubek](https://community.apollographql.com/u/Benoit_Lubek)
#### Post date: [January 26, 2023, 8:48am UTC](https://community.apollographql.com/t/query-batching-in-android-client/4622/6 "2023-01-26T08:48:42Z")

</div>

Hi!

- You can use Java and [Rx with Apollo Kotlin](https://www.apollographql.com/docs/kotlin/advanced/rxjava) but the experience may not be as optimal as using Kotlin and coroutines which is the main way to interact with the library. For a better support of Java, [stay tuned](https://github.com/apollographql/apollo-kotlin/blob/main/ROADMAP.md#better-java-support), as this is part or the roadmap.  
In any case, batching works independently of using Rx or not.
- Currently, there is no API to know whether a particular call was part of a batch or not. Could you tell us a bit more of the use case?
- I think all the available configuration is described in [the doc](https://www.apollographql.com/docs/kotlin/advanced/query-batching) but if you want to explore further, you could have a look at the implementation [here](https://github.com/apollographql/apollo-kotlin/blob/c8d4c75b18172ea5ca30a5965c47ac2a991f8983/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/BatchingHttpInterceptor.kt#L62).

---

<div class="post-metadata">

### Author: ![ashuspeed](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/ashuspeed/32/2422_2.png) [@ashuspeed](https://community.apollographql.com/u/ashuspeed)
#### Post date: [January 26, 2023, 6:21pm UTC](https://community.apollographql.com/t/query-batching-in-android-client/4622/7 "2023-01-26T18:21:50Z")

</div>

Thanks @Benoit_Lubek for the quick response, I was trying Batching by passing callbacks to the query Operation, Since we have a way for query to opt in and out of Batching, my concern was around how to distinguish between the queries that were a part of single batch operations and which got executed outside the batch by looking at their responses.

I can understand that looking at the code can give us a hint but for an end user who got the response. Is their a way to identify it?

Also when the request was fired as a batch operation but due to configuration parameters like (batchIntervalMillis and maxBatchSize), it got split into two batch queries. Is there a way to identify it from their responses or any other metrics using which this information can be identified?

Thanks!!

---

<div class="post-metadata">

### Author: ![Benoit\_Lubek](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/benoit_lubek/32/2070_2.png) [@Benoit\_Lubek](https://community.apollographql.com/u/Benoit_Lubek)
#### Post date: [January 27, 2023, 10:05pm UTC](https://community.apollographql.com/t/query-batching-in-android-client/4622/8 "2023-01-27T22:05:37Z")

</div>

No such API currently exists.

> my concern was around how to distinguish between the queries that were a part of single batch operations and which got executed outside the batch by looking at their responses.

Could you elaborate on why you need this information, at the moment I don’t understand what the end goal is.

Thanks!
