Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sitecore-jss][templates/nextjs] Handle rate limit errors in Layout and Dictionary Services through GraphQL Client #1618

Merged
merged 10 commits into from
Sep 25, 2023

Conversation

art-alexeyenko
Copy link
Contributor

@art-alexeyenko art-alexeyenko commented Sep 24, 2023

Description / Motivation

GraphQL endpoints can reply with a code 429 response when too many requests are launched (i.e. during static page generation). This PR adds a retryer functionality to GraphQL Client in sitecore-jss package to prevent 429 errors crashing a nextjs build.
To enable it, specify the number of retries for GraphQL services in dictionary-service-factory and layout-service-factory.

Retry will either read the 'Retry-After' header and send another request after the specified timespan, or use 1 second between retries by default.

Testing Details

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@art-alexeyenko art-alexeyenko requested a review from a team September 24, 2023 21:35
Copy link
Contributor

@illiakovalenko illiakovalenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen in case of graphql-personalize-service, graphql-redirects-service, etc... all the services that are using GraphQLClient, since you covered only dictionary, layout services?

@art-alexeyenko
Copy link
Contributor Author

What will happen in case of graphql-personalize-service, graphql-redirects-service, etc... all the services that are using GraphQLClient, since you covered only dictionary, layout services?

In case of personalize service that's intentional. We should not have personalize be slow, and if it fails it should fail fast, not wait for one second or more.
In case of others - it's mostly to not complicate the implementation and keep it as far as possible from being a breaking change. The main problem, and the main bulk of requests being sent are dictionary and layout service requests. By addressing those there should be a lot of breathing room for all the rest.
@illiakovalenko

@illiakovalenko
Copy link
Contributor

@art-alexeyenko For example "redirects-service" is called on each request, like dictionary, layout services. What about this case?

@art-alexeyenko
Copy link
Contributor Author

art-alexeyenko commented Sep 25, 2023

For example "redirects-service" is called on each request, like dictionary, layout services. What about this case?

I think retryer is not a good fit for a redirects-service either. Redirects is something that won't be updated too often, is something that isn't too large, and redirects are retrieved on per-site basis. With this, instead of bombarding GQL endpoint with retry redirects queries, it would be better to reduce how often redirect data is fetched - via storing it in app for a certain time. It would be better than retrieving all the redirects for every page render.

@art-alexeyenko art-alexeyenko merged commit d8fa093 into dev Sep 25, 2023
1 check passed
@art-alexeyenko art-alexeyenko deleted the feature/jss-505-handle-rate-limits-gql branch September 25, 2023 16:45
art-alexeyenko added a commit that referenced this pull request Sep 25, 2023
…nd Dictionary Services through GraphQL Client (#1618)

* Retryer in graphql client implementation

(cherry picked from commit d8fa093)
@illiakovalenko illiakovalenko mentioned this pull request Oct 12, 2023
7 tasks
illiakovalenko added a commit that referenced this pull request Oct 12, 2023
* [sitecore-jss-nextjs] Reduce the amount of Edge API calls during fetch `getStaticPaths`  (#1612)

* [sitecore-jss][templates/nextjs][templates/nextjs-sxa] Handle rate limit errors in Layout and Dictionary Services through GraphQL Client

* Updated CHANGELOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants