Square not supporting paralel requests

I am making a SaaS application using Square. For performance reasons when I have to fetch different square api’s within the same functions. I have used Promise.all to ensure all the required request are fetched simoultaneously.But the wierd thing I noticed is that even is I initiate the requests simoultaneously using Promise.all, Square SDK internally makes the request sequentially.

So I made a testing snippet which makes 4 different api call using the sdk and sends them paralelly.

    const catalogSearch = squareClient.catalog.search({
        includeRelatedObjects: true,
    }).then(result => {
        const endTime = Date.now();
        console.log(`Catalog search completed at ${endTime - test4StartTime}ms`);
        return result;
    }).catch(error => {
        const endTime = Date.now();
        console.error(`Catalog search failed at ${endTime - test4StartTime}ms:`, error);
        throw error;
    });
    
    const catalogSearchItems = squareClient.catalog.searchItems({}).then(result => {
        const endTime = Date.now();
        console.log(`Catalog searchItems completed at ${endTime - test4StartTime}ms`);
        return result;
    }).catch(error => {
        const endTime = Date.now();
        console.error(`Catalog searchItems failed at ${endTime - test4StartTime}ms:`, error);
        throw error;
    });

    const locationsList = squareClient.locations.list().then(result => {
        const endTime = Date.now();
        console.log(`Locations list completed at ${endTime - test4StartTime}ms`);
        return result;
    }).catch(error => {
        const endTime = Date.now();
        console.error(`Locations list failed at ${endTime - test4StartTime}ms:`, error);
        throw error;
    });
    
    const locationGet = squareClient.locations.get({ locationId: 'L097HCJ5BRQPS' }).then(result => {
        const endTime = Date.now();
        console.log(`Location get completed at ${endTime - test4StartTime}ms`);
        return result;
    }).catch(error => {
        const endTime = Date.now();
        console.error(`Location get failed at ${endTime - test4StartTime}ms:`, error);
        throw error;
    });
    
    console.log('All 4 different endpoint requests started simultaneously');
    await Promise.all([catalogSearch, catalogSearchItems, locationsList, locationGet]);
    const test4TotalTime = Date.now() - test4StartTime;
    console.log(`All 4 different endpoint requests completed in ${test4TotalTime}ms`);

The console logs achieved from running the following snippet are:Testing calling

different endpoints in parallel:All 4 different endpoint requests started simultaneouslyLocations list completed at 1008msCatalog searchItems completed at 3394msLocation get completed at 3398msCatalog search completed at 6155msAll 4 different endpoint requests completed in 6155m

I then followed to manually run paralell request using manual fetch requests for larger number of simoultaneous request. Just as expected through manual fetch request I can ahieve high concurrency. Whenn using the sdk the requests always go through sequentially.

I tried to search if this is a known issue, or if it is intentional but I was not able to find anything relevant.

How can I send multiple requests concurently using the Square SDK?

:waving_hand: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Synchronize a Catalog with an External Platform
Optimistic Concurrency
Square GraphQL

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

What you’re observing is actually expected behavior from the Square SDK. The SDK includes built-in connection pooling and request queuing mechanisms that are designed to:

  • Prevent overwhelming Square’s API servers
  • Ensure reliable request handling
  • Manage rate limiting more effectively
  • Maintain connection stability

The sequential execution you’re seeing isn’t a bug—it’s a feature that helps maintain optimal performance and reliability when interacting with Square’s APIs.

Square’s APIs have rate limits in place to ensure system stability and fair usage across all developers. The SDK’s internal queuing helps you stay within these limits automatically, rather than requiring you to implement complex retry logic and rate limiting in your application.

Additionally, many Square API endpoints have interdependencies. For example, catalog operations might need to maintain consistency, and the SDK’s sequential processing helps ensure data integrity. :slight_smile:

Thank you for the update on this.
I have a follow up question related to rate limitting. Is the rate limit applied on individual user tokens or at the application level.

Have you looked at using our GraphQL if you need data from multiple endpoints?

As for rate limits Square does have rate limits but we don’t document the limits. We encourage you to handle the limit gracefully by building a retry mechanism. This mechanism should have an exponential backoff schedule to reduce requests when volume is necessary. Also some randomness wouldn’t hurt to avoid a thundering herd effect. :slight_smile:

I hadn’t viewed the GraphQL API yet. This would help alot. Thanks for the update.

Yeah, I would try to incorporate retry mechanisms and handling 429 responses.

Hey @Bryan-Square I have one more question related to the rate limitting within the GraphQL Endpoint.

I read the documentation about rate limitting from the url

The page states that we can send maximum of 10 queries per second with each having a maximum complexity of 250.

If this mentioned rate limit applied at the Application level. Or is the rate limit applied at a user level?

It’s merchant level. :slight_smile:

Appreciate the help!