Skip to main content

Part 4: Rate Limiting

In this tutorial, we will go through everything you need to know to configure Inigo agents for GraphQL rate limiting. We will use a simple rate limiting configuration to restrict the number of requests that can be made to certain GraphQL queries.

Prerequisites

  • Account : create one at app.inigo.io.
  • CLI : install the Inigo cli.
  • We'll use a hosted Starwars Demo service so there is no need to deploy any GraphQL server.

Introduction

When you first login to Inigo, you will see a demo service which is running the Inigo agent on top of a common Starwars GraphQL API. The demo has been pre-populated with some API data, you can browse through the dashboards on the Home tab, and also play with the filters on the Explore tab to see more granular analytics of each request.

Inigo agents are configured using YAML configuration files, similar to Kubernetes or other tools that use the configure-as-code approach. The configuration files live in your repository and the Inigo CLI is used to apply them to running systems. The CLI can be run locally and can be easily integrated into any CI/CD pipeline. Inigo agents automatically pull the latest applied configuration without the need to restart the GraphQL server the agent is running on.

In this tutorial, we'll add a simple rule to restrict the number of requests that can be made to certain GraphQL queries using rate limiting. We will limit the number of requests that can be made to the query.films and query.people queries.

Rate Limiting Configuration

In addition to the configuration done in part 1 & 2, create a file called rate_limit.yml with the following content:

kind: RateLimit
name: demo
label: starwars
spec:
profiles:
- name: guest
path_calls:
- path: query.films
allowance: 5
period: 10m
- path: query.people
allowance: 10
period: 1h30m

The configuration defines two paths, query.films and query.people, and specifies that no more than 5 requests per 10 minutes are allowed for query.films, and no more than 10 requests per 1 hour 30 minutes are allowed for query.people.

Applying the Configuration

Apply the rate limiting configuration using the Inigo CLI:

inigo apply rate_limit.yml

The CLI will upload the configuration file to Inigo and apply it to the running Inigo agent.

Testing the Rate Limiting

Now, try running the Films query more than 5 times in 10 minutes using the playground in the Inigo app.

query Films {
films {
title
}
}

You should see the following error message:

{
"data": null,
"extensions": {},
"errors": [
{
"message": "Rate limit exceeded for query.films"
}
]
}

Similarly, if you try to run the query.people query more than 10 times in 1 hour 30 minutes, you will see a similar rate limit exceeded error.

Congratulations! You have applied your first rate limiting configuration to the Inigo agent. You can now go to the Home and Explore tabs and view the different requests you just ran, including the ones that were blocked due to rate limiting.

Next Steps

Part 4 coming soon with more advanced rate limit configurations.