Bird
0
0

You need to fetch data for 100 items asynchronously but want to limit concurrency to 10 requests at a time to avoid server overload. Which approach correctly implements this in JavaScript?

hard📝 Application Q8 of 15
Rest API - Batch and Bulk Operations
You need to fetch data for 100 items asynchronously but want to limit concurrency to 10 requests at a time to avoid server overload. Which approach correctly implements this in JavaScript?
AProcess the URLs in chunks of 10, awaiting Promise.all for each chunk before proceeding
BSend all 100 fetch requests at once using Promise.all without batching
CUse a forEach loop with async fetch calls without awaiting them
DFetch each URL sequentially using a for loop with await inside
Step-by-Step Solution
Solution:
  1. Step 1: Understand concurrency control

    To limit concurrent requests, divide the total URLs into smaller batches.
  2. Step 2: Implement batching

    Process each batch of 10 URLs with Promise.all and await completion before starting the next batch.
  3. Final Answer:

    Process the URLs in chunks of 10, awaiting Promise.all for each chunk before proceeding -> Option A
  4. Quick Check:

    Batching controls concurrency, prevents overload [OK]
Quick Trick: Batch requests and await each batch to limit concurrency [OK]
Common Mistakes:
MISTAKES
  • Sending all requests simultaneously causing overload
  • Not awaiting fetch calls leading to unhandled promises
  • Fetching sequentially causing slow performance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes