Skip to content

perf: eliminate N+1 Stripe lookups in /products endpoint#378

Open
vincerevu wants to merge 1 commit intostripe:mainfrom
vincerevu:galtee-invoicing-perf-opt-8540215154623050437
Open

perf: eliminate N+1 Stripe lookups in /products endpoint#378
vincerevu wants to merge 1 commit intostripe:mainfrom
vincerevu:galtee-invoicing-perf-opt-8540215154623050437

Conversation

@vincerevu
Copy link
Copy Markdown

Summary

This PR improves /products performance by removing the N+1 Stripe lookup pattern. Instead of making one Stripe request per product to resolve Stripe-specific IDs, it fetches Stripe products once up front and maps them locally using metadata.product_id.

What changed

  • replaced per-product Stripe lookups with a single upfront stripe.products.list call
  • built a local map from metadata.product_id to Stripe product IDs
  • updated product retrieval logic to use local lookups during iteration
  • added benchmark coverage for the optimized /products flow
  • included related benchmark package / lock / ignore file updates

Why

Previously, the retrieval loop made one Stripe request for each configured product, so latency scaled linearly with the size of PRODUCT_CONFIG. This introduced unnecessary network overhead and slower endpoint performance.

Measured improvement

The benchmark simulates 5 serial calls to /products.

  • before the patch: 15 calls to products.list, completed in 758 ms
  • after the patch: 5 calls to products.list, with lower total request overhead

Impact

  • removes the N+1 API call pattern
  • reduces repeated Stripe network I/O
  • improves response time and scalability for product retrieval

Verification

  • added benchmark logic to validate the new behavior
  • confirmed the endpoint now uses one upfront Stripe fetch and local mapping afterward
  • reviewed the related benchmark environment file changes included in the patch

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.

1 participant