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

feat(relay): irn_batchRequest method #222

Open
wants to merge 1 commit into
base: main-lfs-DO-NOT-USE
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/specs/servers/relay/relay-server-rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,32 @@ Used to unregister an active watch webhook corresponding to a webhookId.
}
```

### Batch Request

Allows combining multiple requests into a single one. Used to save on round-trip latency.

```jsonc
// Request (client->server)
{
"id" : "1",
"jsonrpc": "2.0",
"method": "irn_batchRequest",
"params" : {
"batch": Request[],
"mode": "sequence" | "concurrent"
Copy link
Member

Choose a reason for hiding this comment

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

I thought we had a use-case where we need both sequence and concurrent at the same time.
Like:

  • execute 3 requests concurrently
  • afterwards execute another request

Isn't it the case?

Copy link
Author

Choose a reason for hiding this comment

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

Correct. So with the suggested implementation you'd combine requests like this:

{
  "method": "irn_batchRequest",
  "params": {
    "mode": "sequence",
    "batch": [
      // First execute a batch of requests concurrently.
      {
        "method": "irn_batchRequest",
        "params": {
          "mode": "concurrent",
          "batch": [
            // Concurrent requests, e.g. subscriptions.
          ]
        },
        ...
      },

      // Then another request once the first batch is processed.
      {
        "method": "irn_publish",
        ...
      },
    ]
  },
  ...
}

}
}

// Response (server->client)
{
"id" : "1",
"jsonrpc": "2.0",
"result": true
}
```

Requests in the batch are executed either concurrently or in sequence, as specified in the `mode` parameter. Responses to each request in the batch are sent back separately and immediately after the request has been processed. Once all of the requests have been processed, the batch response is sent to the client.

## FAQ

- What is a client? - Any SDK instance (Sign, Chat, Auth, Push)