At a high level the gateway does 2 things:
- Route client requests to indexers
- Facilitate payments to indexers
- The client GraphQL request arrives, including an auth token (API key or query key). The auth token is used to check associated allowlists, payment status, etc.
- Indexers are selected from the set allocated to the subgraph deployment being queried. For queries by subgraph ID (GNS ID), indexers are selected across the allocations on all associated deployments (subgraph versions).
- A subset of up to 3 indexers are selected based on a variety of selection factors including reliability, latency, subgraph version (if applicable), etc.
- The request is made deterministic by replacing block numbers with hashes for the chain being indexed by the subgraph.
- The request is forwarded to each selected indexer.
- Each indexer’s response, latency, etc. is fed back into indexer selection.
- The first valid indexer response is returned it to the client. If no indexers return a valid response goto step 3.
-
The gateway is designed to be a reliable system, to compensate for indexers being relatively unreliable. Indexers may become unresponsive, malicious, or otherwise unsuitable for serving queries at any time without warning. It is the responsibility of the gateway to maintain the highest possible quality of service(QoS) under these conditions.
-
The gateway's primary responsibilities are to serve client requests and to facilitate indexer payments. Other responsibilities, though important, are secondary and therefore their failure modes must have minimal impact on the primary responsibilities.