Bird
Raised Fist0
Postmantesting~15 mins

Delay between requests in Postman - Deep Dive

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Overview - Delay between requests
What is it?
Delay between requests means adding a pause or wait time between sending one request and the next in a sequence. In Postman, this helps control the speed of requests sent to a server. It is useful when testing APIs to avoid overwhelming the server or to simulate real user behavior. This pause can be set to a fixed time or dynamically adjusted.
Why it matters
Without delays, sending many requests quickly can overload servers, causing errors or inaccurate test results. It can also hide real-world issues like rate limiting or server throttling. Adding delays helps testers mimic real user traffic and ensures the server handles requests properly over time. This leads to more reliable and realistic testing outcomes.
Where it fits
Before learning about delays, you should understand how to create and send requests in Postman. After mastering delays, you can explore advanced topics like automated testing, performance testing, and handling rate limits in APIs.
Mental Model
Core Idea
Delay between requests is a controlled pause that spaces out API calls to simulate real usage and protect the server.
Think of it like...
It's like waiting a few seconds between sending letters in the mail instead of sending them all at once, so the post office can handle each properly.
┌───────────────┐   wait   ┌───────────────┐   wait   ┌───────────────┐
│ Request 1    │ ───────> │ Request 2    │ ───────> │ Request 3    │
└───────────────┘         └───────────────┘         └───────────────┘
Build-Up - 6 Steps
1
FoundationWhat is a Request Delay
🤔
Concept: Introducing the basic idea of waiting between API calls.
When you send requests to a server, you can add a pause between each one. This pause is called a delay. It helps control how fast requests go out.
Result
Requests are spaced out instead of sent all at once.
Understanding delay is the first step to controlling request flow and avoiding server overload.
2
FoundationHow to Add Delay in Postman
🤔
Concept: Learning the simple method to add delay using Postman's built-in features.
In Postman, you can add a delay by using the 'setTimeout' function in the 'Tests' or 'Pre-request Script' tab. For example, you can write code to pause before the next request runs.
Result
Postman waits the specified time before sending the next request.
Knowing where and how to add delay in Postman scripts lets you control request timing easily.
3
IntermediateUsing setTimeout for Delays
🤔Before reading on: do you think setTimeout pauses the entire Postman runner or just delays the next request? Commit to your answer.
Concept: Understanding how setTimeout works in Postman scripting to create delays.
setTimeout schedules a function to run after a delay but does not pause the whole script. In Postman, you can use it to delay actions but must manage asynchronous behavior carefully.
Result
Delays happen without freezing Postman, but timing must be managed to ensure requests wait properly.
Knowing setTimeout's asynchronous nature prevents mistakes where delays don't work as expected.
4
IntermediateControlling Delay in Collection Runner
🤔Before reading on: can you set a fixed delay between requests directly in Postman's Collection Runner? Commit to yes or no.
Concept: Learning how to set delays between requests when running collections in Postman.
Postman's Collection Runner has a 'Delay' option where you can specify milliseconds to wait between each request automatically. This is easier than scripting delays manually.
Result
Requests run one after another with the chosen delay in between.
Using Collection Runner's delay feature simplifies adding consistent pauses during batch testing.
5
AdvancedDynamic Delays Based on Response
🤔Before reading on: do you think delays can change depending on server response times? Commit to yes or no.
Concept: Introducing how to adjust delays dynamically using response data or conditions.
You can write scripts in Postman to read server responses and decide how long to wait before the next request. For example, wait longer if the server is slow or rate limiting.
Result
Delays adapt to server behavior, making tests more realistic and robust.
Dynamic delays help simulate real user pacing and handle server limits gracefully.
6
ExpertAvoiding Delay Pitfalls in Automation
🤔Before reading on: do you think adding too long delays always improves test reliability? Commit to yes or no.
Concept: Understanding the tradeoffs and risks of delays in automated testing workflows.
Too long delays slow tests and waste time, while too short delays risk server errors. Balancing delay length is key. Also, some CI/CD tools may timeout if delays are excessive.
Result
Tests run efficiently without false failures or wasted time.
Knowing when and how much to delay avoids common automation traps and keeps tests reliable and fast.
Under the Hood
Postman runs requests sequentially or in parallel depending on configuration. Delays are implemented by scheduling the next request after a timer expires, either via built-in runner delay or JavaScript timers like setTimeout. This does not block the entire Postman process but controls when the next request starts.
Why designed this way?
Delays were designed to prevent overwhelming servers and to simulate real user behavior. Using asynchronous timers allows Postman to remain responsive and flexible, letting users script complex timing without freezing the interface.
┌───────────────┐
│ Request 1    │
└──────┬────────┘
       │
       ▼ delay timer expires
┌───────────────┐
│ Request 2    │
└──────┬────────┘
       │
       ▼ delay timer expires
┌───────────────┐
│ Request 3    │
└───────────────┘
Myth Busters - 3 Common Misconceptions
Quick: Does setTimeout pause the entire Postman runner? Commit to yes or no.
Common Belief:setTimeout pauses everything in Postman until the delay finishes.
Tap to reveal reality
Reality:setTimeout only schedules a function to run later; it does not block or pause Postman.
Why it matters:Misunderstanding this causes delays to be ineffective or tests to run too fast, missing the intended pause.
Quick: Can you set delay between requests only by adding wait code inside one request? Commit to yes or no.
Common Belief:Adding delay code inside a single request script automatically delays the next request.
Tap to reveal reality
Reality:Delays inside one request script do not pause the Collection Runner; you must use the runner's delay setting or manage asynchronous flow carefully.
Why it matters:This leads to tests running without intended delays, causing server overload or inaccurate timing.
Quick: Does adding longer delays always make tests more reliable? Commit to yes or no.
Common Belief:Longer delays always improve test reliability by giving servers more time.
Tap to reveal reality
Reality:Excessive delays slow tests unnecessarily and can cause timeouts in automation pipelines.
Why it matters:Over-delaying wastes resources and may cause CI/CD failures, reducing test efficiency.
Expert Zone
1
Delays can be combined with conditional logic to skip or shorten waits based on previous request success or failure.
2
Some APIs enforce rate limits that require dynamic delay adjustments to avoid blocking or throttling.
3
Postman's asynchronous scripting model means delays must be carefully managed to avoid race conditions or premature request firing.
When NOT to use
Avoid delays when testing server performance under load or stress, where rapid-fire requests are needed. Instead, use dedicated load testing tools like JMeter or k6.
Production Patterns
In real projects, delays are used to simulate user think time, handle API rate limits gracefully, and prevent flaky tests caused by server overload. Teams often combine fixed delays with dynamic adjustments based on response headers.
Connections
Rate Limiting
Delay between requests helps manage and respect API rate limits.
Understanding delays clarifies how to avoid hitting rate limits and triggering server blocks.
Load Testing
Delays contrast with load testing where rapid requests simulate heavy traffic.
Knowing when to use delays versus rapid requests helps choose the right testing approach.
Traffic Shaping in Networking
Both delay between requests and traffic shaping control flow to prevent overload.
Recognizing this connection shows how software testing borrows ideas from network management to protect systems.
Common Pitfalls
#1Assuming setTimeout pauses the entire test run.
Wrong approach:setTimeout(() => {}, 5000); // expecting this to pause the runner
Correct approach:Use Collection Runner's delay setting or chain requests with proper async handling.
Root cause:Misunderstanding JavaScript's asynchronous timers as blocking calls.
#2Adding delay code only inside one request script expecting it to delay next requests.
Wrong approach:pm.test('delay', () => { setTimeout(() => {}, 3000); });
Correct approach:Set delay in Collection Runner or use async/await with Promises to control flow.
Root cause:Not realizing that script delays inside one request do not affect the runner's request scheduling.
#3Using very long fixed delays to fix flaky tests.
Wrong approach:Setting 10000 ms delay between requests to avoid failures.
Correct approach:Analyze root causes and use dynamic delays or retries instead.
Root cause:Believing longer waits always solve timing issues without investigating underlying problems.
Key Takeaways
Delay between requests spaces out API calls to simulate real user behavior and protect servers.
Postman offers built-in delay settings and scripting options to control request timing effectively.
Understanding asynchronous timers like setTimeout is crucial to implementing delays correctly.
Dynamic delays based on server responses improve test realism and handle rate limits gracefully.
Overusing delays can slow tests unnecessarily; balance is key for reliable and efficient testing.

Practice

(1/5)
1. What is the main purpose of adding a delay between requests in Postman?
easy
A. To change the request URL dynamically
B. To speed up the test execution
C. To skip some requests automatically
D. To simulate real user behavior and avoid server overload

Solution

  1. Step 1: Understand delay usage in Postman

    Delays are used to mimic real user wait times and prevent sending too many requests too fast.
  2. Step 2: Identify the correct purpose

    Speeding up tests or skipping requests are not related to delays; delays help simulate real scenarios and protect servers.
  3. Final Answer:

    To simulate real user behavior and avoid server overload -> Option D
  4. Quick Check:

    Delay purpose = simulate real use and avoid overload [OK]
Hint: Delays mimic real users and protect servers from overload [OK]
Common Mistakes:
  • Thinking delays speed up tests
  • Confusing delay with skipping requests
  • Assuming delay changes request data
2. Which of the following is the correct way to add a 2-second delay between requests in Postman using JavaScript?
easy
A. delay(2000); postman.setNextRequest('Request2');
B. postman.setNextRequest('Request2', 2000);
C. setTimeout(() => postman.setNextRequest('Request2'), 2000);
D. setTimeout(postman.setNextRequest('Request2'), 2000);

Solution

  1. Step 1: Recall correct setTimeout syntax

    setTimeout takes a function and delay in milliseconds: setTimeout(function, delay).
  2. Step 2: Check usage with postman.setNextRequest

    postman.setNextRequest must be called inside a function passed to setTimeout to delay execution.
  3. Final Answer:

    setTimeout(() => postman.setNextRequest('Request2'), 2000); -> Option C
  4. Quick Check:

    Use setTimeout with function and delay [OK]
Hint: Wrap setNextRequest in a function inside setTimeout [OK]
Common Mistakes:
  • Passing setNextRequest call directly to setTimeout
  • Using non-existent delay function
  • Trying to pass delay as second argument to setNextRequest
3. Given this Postman test script snippet, what will happen?
setTimeout(() => postman.setNextRequest('Login'), 3000);
console.log('Request scheduled');
medium
A. The 'Login' request will run immediately, and 'Request scheduled' logs after 3 seconds
B. 'Request scheduled' logs immediately, and 'Login' request runs after 3 seconds
C. Both 'Login' request and log happen immediately
D. Neither 'Login' request nor log will run

Solution

  1. Step 1: Understand setTimeout behavior

    setTimeout delays the function call (postman.setNextRequest) by 3000 ms, but console.log runs immediately.
  2. Step 2: Determine order of execution

    console.log('Request scheduled') runs first; after 3 seconds, the 'Login' request is set to run next.
  3. Final Answer:

    'Request scheduled' logs immediately, and 'Login' request runs after 3 seconds -> Option B
  4. Quick Check:

    console.log immediate, setNextRequest delayed [OK]
Hint: console.log runs immediately; setNextRequest delayed by setTimeout [OK]
Common Mistakes:
  • Assuming setNextRequest runs immediately
  • Thinking console.log waits for delay
  • Confusing order of asynchronous calls
4. You wrote this Postman script to delay the next request by 1 second, but the delay does not work. What is wrong?
setTimeout(postman.setNextRequest('NextRequest'), 1000);
medium
A. postman.setNextRequest should be inside a function passed to setTimeout
B. Delay time should be in seconds, not milliseconds
C. setTimeout cannot be used in Postman scripts
D. postman.setNextRequest does not accept request names

Solution

  1. Step 1: Analyze setTimeout usage

    setTimeout expects a function as first argument, but here postman.setNextRequest is called immediately.
  2. Step 2: Correct usage for delay

    Wrap postman.setNextRequest call inside a function (e.g., arrow function) to delay execution properly.
  3. Final Answer:

    postman.setNextRequest should be inside a function passed to setTimeout -> Option A
  4. Quick Check:

    Pass function to setTimeout, not direct call [OK]
Hint: Wrap setNextRequest call in a function for setTimeout delay [OK]
Common Mistakes:
  • Passing direct call instead of function to setTimeout
  • Confusing milliseconds with seconds
  • Believing setTimeout is unsupported in Postman
5. You want to run three requests in sequence with a 1-second delay between each in Postman. Which script correctly implements this in the Tests tab of the first request?
hard
A. setTimeout(() => { postman.setNextRequest('Request2'); setTimeout(() => postman.setNextRequest('Request3'), 1000); }, 1000);
B. setTimeout(() => postman.setNextRequest('Request2'), 1000);
C. postman.setNextRequest('Request2'); setTimeout(() => postman.setNextRequest('Request3'), 1000);
D. postman.setNextRequest('Request2'); postman.setNextRequest('Request3');

Solution

  1. Step 1: Understand sequential delays

    Each request must be delayed before triggering the next; nested setTimeout calls create sequential delays.
  2. Step 2: Analyze options

    setTimeout(() => { postman.setNextRequest('Request2'); setTimeout(() => postman.setNextRequest('Request3'), 1000); }, 1000); nests setTimeout calls to delay Request2 by 1s, then Request3 by another 1s, correctly sequencing requests with delays.
  3. Final Answer:

    setTimeout(() => { postman.setNextRequest('Request2'); setTimeout(() => postman.setNextRequest('Request3'), 1000); }, 1000); -> Option A
  4. Quick Check:

    Nested setTimeouts create sequential delays [OK]
Hint: Use nested setTimeouts to delay multiple requests sequentially [OK]
Common Mistakes:
  • Calling setNextRequest multiple times without delay
  • Not nesting delays causing immediate requests
  • Assuming one setTimeout delays all requests