tailcall icon indicating copy to clipboard operation
tailcall copied to clipboard

Guide: Write a guide about Batching

Open tusharmath opened this issue 1 year ago • 18 comments

Write a guide about the batching capabilities of Tailcall. Consider a food delivery application where a lot of users are requesting the same data. Batching could be implemented based on GEO Location / City / Locality etc. Emphasize on the impact it has on performance and how it can help scale. Consider the backend to be in REST.

Content Creation Requirements

To maintain the quality of our content, please adhere to the following guidelines:

1. Accuracy in Language

  • Grammar and Spelling: Ensure your content is free from grammatical and spelling errors.

2. Tone and Style

  • Neutral Tone: Maintain a neutral, non-emotional tone throughout the content.
  • Engaging Style: Write in a free-flowing and engaging manner, keeping the reader's interest.

3. Content Integrity

  • Fact-Checking: Verify all information. If unsure, use Discord to clarify.
  • Relevance: Ensure all content is cohesive, to the point, and directly related to the title.

4. Originality

  • Avoid Low-Effort Content: Content should be original and not solely generated by AI tools like ChatGPT.

PS: Adherence to these guidelines is crucial. Content not meeting these standards may require revision or may not be accepted.

tusharmath avatar Jan 03 '24 06:01 tusharmath

/bounty 120$

tusharmath avatar Jan 03 '24 06:01 tusharmath

💎 $120 bounty • Tailcall Inc.

Steps to solve:

  1. Start working: Comment /attempt #882 with your implementation plan
  2. Submit work: Create a pull request including /claim #882 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

🙏 Thank you for contributing to tailcallhq/tailcall! 🧐 Checkout our guidelines before you get started. 💵 More about our bounty program.

algora-pbc[bot] avatar Jan 03 '24 06:01 algora-pbc[bot]

can i get assigned?

ibishal avatar Jan 03 '24 06:01 ibishal

Interested in working on this ✋.

ayewo avatar Jan 03 '24 06:01 ayewo

@tusharmath please assign it to me

ayusham001 avatar Jan 03 '24 07:01 ayusham001

@tusharmath brother, I'm interested to work on this.

nxshanth13 avatar Jan 04 '24 02:01 nxshanth13

Assign it to me, i can do it.

FaizanShaikh-3033 avatar Jan 04 '24 03:01 FaizanShaikh-3033

Have not seen any progress on this issue, unassigning it from @ayewo, let me know if someone wants to work it.

tusharmath avatar Jan 15 '24 11:01 tusharmath

@tusharmath i would love to work on that Please assign it to me

ayusham001 avatar Jan 15 '24 11:01 ayusham001

@tusharmath was about open a PR ...

While writing this, I ran into some gaps in Tailcall's implementation of batching, and more generally, about how the @http operator works.

  1. We need a jsonpath attribute to be added to the @http(...) operator so it is easy to index inside JSON responses returned by upstream endpoints.
  • 1a. The https://jsonplaceholder.typicode.com/users URL uses a top-level array for its JSON and it's response is shaped like this:
[
  {...},
   ...,
  {...}
]
  • 1b. This URL https://dummyjson.com/users doesn't use a top-level array for its JSON due to its inclusion of pagination attributes so it's JSON is shaped like this:
{
  "users": [{...}, ..., {...}],
  "total": 100,
  "skip": 0,
  "limit": 30
}

This difference in output is why the 2nd URL fails in Tailcall with the following error i.e.

{
  "data": null,
  "errors": [
    {
      "message": "internal: expects an array",
      "locations": [
        {
          "line": 33,
          "column": 3
        }
      ],
      "path": [
        "users"
      ]
    }
  ]
}

Once implemented, we could use a splat expression[^splat] inside the jsonpath to target the data we need:

  type Query {
  users: [User]! @http(path: "/users", jsonpath: "users.[*]")
}
  1. Batching only supports use of keys that appear in the query params.
  • 2a. Batching works with query params URLs: https://example.com/path/users?id=1&id=4&id=7 where the query param id is also used for groupBy i.e. @http(path: "/users", query: [{key: "id", value: "{{value.userId}}"}], groupBy: ["id"])

  • 2b. Batching doesn't work with multiple path params URLs: https://example.com/path/users/1,4,7 where the path params implies bulk fetch 3 users with the IDs 1, 4, & 7 i.e. https://example.com/path/users/1, https://example.com/path/users/4, and https://example.com/path/users/7).

ipstack.com is an example of an API designed to only support multiple path params for bulk requests.[^note2]

Batching on ipstack.com is done by comma-separating multiple path params when constructing a bulk request:

http://api.ipstack.com/134.201.250.155,72.229.28.185,110.174.165.78
    ? access_key = YOUR_ACCESS_KEY

When called from a schema @http(baseURL: "http://api.ipstack.com", path: "/{{value.ip}}", groupBy: ["ip"]), Tailcall assumes the request is missing query params so it fails with the following error:

{
  "data": null,
  "errors": [
    {
      "message": "IOException: Unable to find key ip in query params",
      "locations": [
        {
          "line": 39,
          "column": 5
        }
      ]
    }
  ]
}

[^splat]: Splat expressions in HCL

[^note2]: Similarly ip-api.com, ipdata.co and ipinfo.io are 3 geolocation services whose batching endpoint will not work with Tailcall as it can only be done over POST. Tailcall only supports batching over GET requests. When I tested ip-api.com in a schema via @http(baseURL: "http://ip-api.com", path: "/batch", method: POST, body: ...), the Tailcall server failed with Error: Invalid Configuration caused by GroupBy is only supported for GET requests.

ayewo avatar Jan 15 '24 13:01 ayewo

👋 Hey Tushar,

I am interested in your task and available to start immediately.

I am experienced with Docusaurus.io, Nextra, Mkdocs, and markdown. I can provide you with a user-friendly guide.

Here are some of my live guides:

I'm looking forward to hearing from you soon 😃 Contact me and let's get started.

AbdoALPOP avatar Jan 20 '24 20:01 AbdoALPOP

💡 @ayewo submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] avatar Jan 22 '24 14:01 algora-pbc[bot]

Action required: Issue inactive for 30 days. Status update or closure in 7 days.

github-actions[bot] avatar Feb 21 '24 15:02 github-actions[bot]

.

ayewo avatar Feb 21 '24 16:02 ayewo

Action required: Issue inactive for 30 days. Status update or closure in 7 days.

github-actions[bot] avatar Mar 22 '24 18:03 github-actions[bot]

.

ayewo avatar Mar 22 '24 20:03 ayewo

Action required: Issue inactive for 30 days. Status update or closure in 7 days.

github-actions[bot] avatar May 06 '24 18:05 github-actions[bot]

.

ayewo avatar May 06 '24 20:05 ayewo

.

ayewo avatar Jun 05 '24 14:06 ayewo

/tip 20$

tusharmath avatar Jun 06 '24 06:06 tusharmath

@ayewo Apologies, this has taken too long. Unfortunately, I don't think this in line with what we expected, and the to and fro on the discussion did not seem like is going anywhere. The content is too long and sort of distracts us from the main topic. I appreciate you putting time in creating this PR and hope to see more from you in the future 🙌

Once again, sorry for not responding sooner.

tusharmath avatar Jun 06 '24 06:06 tusharmath

@ayewo Apologies, this has taken too long. Unfortunately, I don't think this in line with what we expected, and the to and fro on the discussion did not seem like is going anywhere. The content is too long and sort of distracts us from the main topic. I appreciate you putting time in creating this PR and hope to see more from you in the future 🙌

Once again, sorry for not responding sooner.

@tusharmath well, I tried to suggest on Discord, two months ago, that Tailcall pay for the content produced so far since everything was taking to long already …

Glad you finally decided to do this but the tip is really 😏. Can you please make it $50?

Also, you’ll need to include the GitHub username for the tip command to work from here (or do it directly on the PR without the username as you did above) i.e.:

/tip $50 @ayewo 

ayewo avatar Jun 06 '24 08:06 ayewo