Skip to content

fix(tier-client): avoid 414 URI Too Large on orgs with many enrollments#1390

Merged
ekremney merged 1 commit intomainfrom
fix/tier-client-414-uri-too-large
Mar 1, 2026
Merged

fix(tier-client): avoid 414 URI Too Large on orgs with many enrollments#1390
ekremney merged 1 commit intomainfrom
fix/tier-client-414-uri-too-large

Conversation

@ekremney
Copy link
Member

@ekremney ekremney commented Mar 1, 2026

Summary

  • Root cause: After migrating from DynamoDB to PostgREST, batchGetByKeys generates GET requests with ?id=in.(uuid1,uuid2,...) in the URL. For orgs with hundreds of site enrollments, this exceeds HTTP URL length limits causing 414 Request-URI Too Large.
  • getAllEnrollment(): When a specific site is provided, skips batch fetch entirely and uses a single findById call. For org-only path, chunks batchGetByKeys into groups of 50 IDs (~1,800 chars per chunk, well under 8KB limit).
  • getFirstEnrollment(): Now standalone (no longer calls getAllEnrollment). Site-specific path does in-memory match and returns this.site directly. Org-only path iterates enrollments with findById one at a time with early exit on first match.

Test plan

  • All 70 unit tests pass
  • 100% code coverage (statements, branches, functions, lines)
  • ESLint clean
  • Deploy to dev and test sites-resolve endpoint with AEM Reference Demo org (the org that was hitting 414)
  • Verify login flow works for orgs with many enrollments

🤖 Generated with Claude Code

Rewrite getAllEnrollment() and getFirstEnrollment() to eliminate the
oversized GET URLs that PostgREST generates when batchGetByKeys is
called with hundreds of UUIDs.

- getAllEnrollment: site-specific path uses findById instead of
  batchGetByKeys; org-only path chunks batchGetByKeys into groups of 50
- getFirstEnrollment: now standalone (no longer calls getAllEnrollment);
  site-specific path does in-memory match; org-only path iterates with
  findById and early exit

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ekremney ekremney requested review from ravverma and solaris007 March 1, 2026 15:24
Copy link
Member

@solaris007 solaris007 left a comment

Choose a reason for hiding this comment

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

Clean fix for the 414 URI Too Large on orgs with many enrollments.

getAllEnrollment() changes:

  • Site-specific path: single findById instead of batch fetch of all sites
  • Org-only path: chunks batchGetByKeys into groups of 50 - fixes the 414 while preserving existing behavior

getFirstEnrollment() rewrite:

  • Now standalone - no longer calls getAllEnrollment() which was wasteful (fetching ALL sites just to return one)
  • Site-specific path: in-memory filter + returns this.site directly - zero DB calls for the site
  • Org-only path: iterates with findById + early exit on first match

Test coverage looks solid - 70 tests, 100% coverage, edge cases covered.

One note: The org-only getFirstEnrollment does sequential findById calls in a loop. Fine for this use case (early exit), but if most enrollments pointed to sites in other orgs it could make many individual calls before finding a match. Not a practical concern since enrollments are typically scoped correctly - just worth being aware of.

LGTM.

@ekremney ekremney merged commit 2e9de5e into main Mar 1, 2026
7 checks passed
@ekremney ekremney deleted the fix/tier-client-414-uri-too-large branch March 1, 2026 15:28
solaris007 pushed a commit that referenced this pull request Mar 1, 2026
## [@adobe/spacecat-shared-tier-client-v1.3.13](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tier-client-v1.3.12...@adobe/spacecat-shared-tier-client-v1.3.13) (2026-03-01)

### Bug Fixes

* **tier-client:** avoid 414 URI Too Large on orgs with many enrollments ([#1390](#1390)) ([2e9de5e](2e9de5e))
@solaris007
Copy link
Member

🎉 This PR is included in version @adobe/spacecat-shared-tier-client-v1.3.13 🎉

The release is available on:

Your semantic-release bot 📦🚀

ekremney added a commit that referenced this pull request Mar 1, 2026
)

## Summary

- PostgREST `batchGetByKeys` uses `.in(field, values)` which generates
GET URLs like `?id=in.(uuid1,uuid2,...)`. With hundreds of keys, this
exceeds HTTP URL length limits causing **414 Request-URI Too Large**.
- Splits the `.in()` call into chunks of 50 keys (~1,800 chars per
chunk, well under the 8KB URL limit) and merges results.
- This is a defense-in-depth fix at the data-access layer. All callers
of `batchGetByKeys` are now automatically protected. See also #1390 for
the TierClient-specific fix.

## Test plan

- [x] All 121 base collection unit tests pass
- [x] New test verifies 120 keys are split into 3 chunks (50 + 50 + 20)
- [x] Existing tests unchanged and passing (small batches still use a
single `.in()` call)
- [x] ESLint clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
solaris007 pushed a commit that referenced this pull request Mar 1, 2026
## [@adobe/spacecat-shared-data-access-v3.4.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.4.0...@adobe/spacecat-shared-data-access-v3.4.1) (2026-03-01)

### Bug Fixes

* **data-access:** chunk batchGetByKeys to avoid 414 URI Too Large ([#1391](#1391)) ([25b0c0d](25b0c0d)), closes [#1390](#1390)
ekremney added a commit that referenced this pull request Mar 4, 2026
…roposal

- Distinguish between individually-inefficient methods and methods called
  in N+1 patterns by consumers
- Split checkValidEntitlement replacement into org-only and with-site variants
- Acknowledge product-specific business logic concern for createEntitlement
- Add migration note about plain objects vs model instances
- Reference PRs #1390 and #1391 for chunking context
- Add trailing newline

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants