Implement paginated retrieval of transactions
Problem: Paginated Transaction Retrieval
Given a large dataset of transaction records, each containing an id, userId, amount, and createdAt timestamp, implement APIs to retrieve these transactions. The retrieval must support pagination and return transactions in reverse chronological order.
Requirements:
- Pagination Modes: Support both offset-based and cursor-based pagination.
- For cursor-based pagination, the cursor should be based on
(createdAt, id).
- For cursor-based pagination, the cursor should be based on
- Response Structure: For each paginated request, return the page data (the list of transactions) along with metadata.
- Metadata must include
hasNext(a boolean indicating if more pages exist) andnextCursor(for cursor-based pagination). - For offset-based pagination, the metadata must also include
total(the total number of transactions matching the criteria).
- Metadata must include
- Stable Ordering: Ensure that the order of transactions is stable and deterministic, even when multiple transactions share the exact same
createdAttimestamp. - Consistency: Discuss strategies to maintain consistent results across multiple paginated requests, especially when new transaction records are being added concurrently.
- Analysis: Provide a detailed analysis of the time and space complexities for your proposed solution, and identify key edge cases that need to be handled.
AI interview prep
Core dilemma
Balancing efficient, scalable pagination (especially cursor-based) with strong data consistency guarantees in a highly concurrent, mutable dataset, while ensuring stable ordering and handling the performance implications of 'total' counts.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement paginated retrieval of transactions
Problem: Paginated Transaction Retrieval
Given a large dataset of transaction records, each containing an id, userId, amount, and createdAt timestamp, implement APIs to retrieve these transactions. The retrieval must support pagination and return transactions in reverse chronological order.
Requirements:
- Pagination Modes: Support both offset-based and cursor-based pagination.
- For cursor-based pagination, the cursor should be based on
(createdAt, id).
- For cursor-based pagination, the cursor should be based on
- Response Structure: For each paginated request, return the page data (the list of transactions) along with metadata.
- Metadata must include
hasNext(a boolean indicating if more pages exist) andnextCursor(for cursor-based pagination). - For offset-based pagination, the metadata must also include
total(the total number of transactions matching the criteria).
- Metadata must include
- Stable Ordering: Ensure that the order of transactions is stable and deterministic, even when multiple transactions share the exact same
createdAttimestamp. - Consistency: Discuss strategies to maintain consistent results across multiple paginated requests, especially when new transaction records are being added concurrently.
- Analysis: Provide a detailed analysis of the time and space complexities for your proposed solution, and identify key edge cases that need to be handled.