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

[FEATURE REQ] Enhance findByIds to Use readMany for Partition Key Optimized Queries or Provide Direct Support for readMany in Spring Data Cosmos SDK #43666

Open
aanaji opened this issue Jan 2, 2025 · 2 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@aanaji
Copy link

aanaji commented Jan 2, 2025

In Cosmos DB, the readMany API provides a more efficient way to fetch multiple items when their id values align with the partition key. However, in the Spring Data Cosmos SDK, the findByIds method does not currently leverage this optimisation. Supporting readMany in findByIds or providing explicit support for readMany in the SDK would significantly improve performance and reduce RU consumption for such use cases.

Proposed Solution:

  1. Enhance findByIds:

    • Automatically detect when the id parameter matches the partition key.
    • Use the readMany API internally in such cases to optimise performance.
  2. Direct Support for readMany:

    • Provide a new method, e.g., readManyByIds, in the Spring Data Cosmos SDK to allow developers to explicitly utilize the readMany API.
    • This method could accept a list of IDs and their corresponding partition keys to fetch the documents efficiently.

Use Case:

  • Scenario: Fetching multiple records by their IDs where id is also the partition key.
  • Benefits:
    • Reduces the number of round-trips to Cosmos DB.
    • Lowers RU consumption compared to fetching items individually.

Expected Behavior:

  • When id matches the partition key, findByIds should leverage the readMany API.
  • For the readManyByIds method, developers can explicitly specify the usage of readMany.

References:

Impact:

  • Improves performance and reduces RU costs in high-throughput applications.
@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. labels Jan 2, 2025
Copy link

github-actions bot commented Jan 2, 2025

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kushagraThapar @pjohari-ms @TheovanKraay.

@kushagraThapar
Copy link
Member

@trande4884 can you please take a look at this, thanks!

@trande4884 trande4884 self-assigned this Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

3 participants