Skip to content

Refactor Azure read model search to use Cosmos DB's native continuation token pagination #1587

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

Merged
merged 18 commits into from
Aug 22, 2025

Conversation

MarcAstr0
Copy link
Collaborator

@MarcAstr0 MarcAstr0 commented Aug 18, 2025

Description

Currently, the implementation for read model search queries in the Azure provider uses custom pagination based on OFFSET and LIMIT. This approach is causing records to either not appear in pages or be duplicated between pages, The root cause is that Cosmos DB does not guarantee consistent ordering for SQL queries without an explicit ORDER BY clause, meaning that the same query can return results in different orders between page requests. This makes OFFSET-based pagination unreliable even without concurrent writes to the container. Additionally, the current cursor calculation logic simply increments by the limit size, which assumes no gaps in data and stable ordering. Using Cosmos DB's native continuation token pagination should correct this.

Changes

  • Refactors the search() method in query-helper.ts to handle paginated queries using the continuation token.

Checks

  • Project Builds
  • Project passes tests and checks
  • Updated documentation accordingly

Castro, Mario added 2 commits August 18, 2025 16:07
It refactors the search method in query
helper of the Azure provider so it uses the
continuation token instead of OFFSET and
LIMIT for proper pagination.
Copy link

what-the-diff bot commented Aug 18, 2025

PR Summary

  • Introduction of Tracking JSON File for Pagination Feature
    A new JSON file has been integrated to facilitate the tracking of changes related to the pagination feature of the Azure provider. This will help in keeping a record and understanding the history of modifications related to this particular functionality.

  • Improved Query Handling Performance with Continuation Token Pagination
    The query-helper.ts file has been updated to optimize performance and offer more flexibility. It now includes the continuation token pagination of Cosmos DB.

  • Ensuring Backward Compatibility with Legacy Cursor Handling
    For the ease of transition and to maintain support for older versions, legacy cursor handling has been incorporated into the system. This ensures that our existing users don't face any issues during the updating process.

  • Enriched Resource Mapping with boosterMetadata
    The resource mapping has been expanded to incorporate boosterMetadata along with optimisticConcurrencyValue. This enhances the overall data representation and gives us more depth in the information that we have about our resources.

  • Updated Final Query Logic for Different Response Types
    The logic used for the final query has been amended to account for both paginated and non-paginated responses. This refinement enables our system to be more responsive and adaptive to different types of feedback.

Copilot

This comment was marked as outdated.

@MarcAstr0
Copy link
Collaborator Author

/integration sha=df95c11

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

❌ Oh no! Integration tests have failed

@MarcAstr0
Copy link
Collaborator Author

/integration sha=7f4ef3b

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

❌ Oh no! Integration tests have failed

Adds console.log messages for debugging event e2e integration tests
@MarcAstr0
Copy link
Collaborator Author

/integration sha=6b448ad

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

❌ Oh no! Integration tests have failed

@MarcAstr0
Copy link
Collaborator Author

/integration sha=8b5abd15

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

❌ Oh no! Integration tests have failed

@MarcAstr0
Copy link
Collaborator Author

/integration sha=f1fdc38c

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

❌ Oh no! Integration tests have failed

@MarcAstr0
Copy link
Collaborator Author

/integration sha=52e8593a

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

❌ Oh no! Integration tests have failed

@MarcAstr0
Copy link
Collaborator Author

/integration sha=5565998a

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

❌ Oh no! Integration tests have failed

@MarcAstr0
Copy link
Collaborator Author

/integration sha=4676cb04

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

✅ Integration tests have finished successfully!

Copy link
Contributor

❌ Oh no! Integration tests have failed

@MarcAstr0
Copy link
Collaborator Author

/integration sha=01ac907e

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

@MarcAstr0 MarcAstr0 requested a review from Copilot August 20, 2025 22:27
Copilot

This comment was marked as outdated.

@MarcAstr0 MarcAstr0 requested a review from Copilot August 20, 2025 22:31
Copilot

This comment was marked as outdated.

Copy link
Contributor

✅ Integration tests have finished successfully!

Copy link
Collaborator

@davidverdu davidverdu left a comment

Choose a reason for hiding this comment

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

Approved with a comment. I would add an integration test or a test in packages/framework-provider-azure/test/helpers/query-helper.test.ts to ensure all the paths of the new code are successfully executed

@MarcAstr0 MarcAstr0 requested a review from Copilot August 22, 2025 14:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the Azure read model search implementation to address pagination issues caused by unreliable OFFSET/LIMIT pagination in Cosmos DB. The implementation now uses Cosmos DB's native continuation token pagination for consistent results while maintaining backward compatibility with existing cursor formats.

  • Replaced custom OFFSET/LIMIT pagination with Cosmos DB's continuation token system for reliable pagination
  • Added backward compatibility logic to handle legacy numeric cursors and DISTINCT queries that require OFFSET/LIMIT fallback
  • Updated integration tests to handle both continuation token and legacy cursor formats

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
query-helper.ts Core refactoring of search method to implement continuation token pagination with fallback logic
read-models.integration.ts Updated test expectations to handle both continuation token and legacy cursor formats
events.integration.ts Added generic cursor type definition for flexible pagination handling
cosmos_db_pagination_2025-08-18-20-09.json Added changelog entry documenting the pagination fix

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@MarcAstr0
Copy link
Collaborator Author

/integration sha=1aff1c9c

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

❌ Oh no! Integration tests have failed

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

✅ Integration tests have finished successfully!

@MarcAstr0 MarcAstr0 merged commit cbac6d6 into boostercloud:main Aug 22, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants