You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
📋 **[View Test Documentation](./test-cli/README.md)** • **[Run Tests Locally](./test-cli/)**
78
+
79
+
---
80
+
50
81
## 📦 Installation
51
82
52
83
### NPM/Yarn (All Frameworks)
@@ -419,6 +450,213 @@ const api = createLuminara({
419
450
420
451
---
421
452
453
+
## 🏎️ Request Hedging
454
+
455
+
Request hedging sends multiple concurrent or sequential requests to reduce latency by racing against slow responses. This is particularly effective for high-latency scenarios where P99 tail latencies impact user experience.
456
+
457
+
### When to Use Hedging
458
+
459
+
**Use hedging when:**
460
+
- High P99 latencies are impacting user experience
461
+
- Idempotent read operations (GET, HEAD, OPTIONS)
462
+
- Server-side variability is high (cloud, microservices)
463
+
- Cost of duplicate requests is acceptable
464
+
465
+
**Don't use hedging when:**
466
+
- Non-idempotent operations (POST, PUT, DELETE)
467
+
- Bandwidth is severely constrained
468
+
- Server capacity is limited
469
+
- Operations have side effects
470
+
471
+
### Basic Race Policy
472
+
473
+
Race policy sends multiple concurrent requests and uses the first successful response:
474
+
475
+
```js
476
+
constapi=createLuminara({
477
+
hedging: {
478
+
policy:'race',
479
+
hedgeDelay:1000, // Wait 1s before sending hedge
480
+
maxHedges:2// Up to 2 hedge requests
481
+
}
482
+
});
483
+
484
+
// Timeline:
485
+
// T+0ms: Primary request sent
486
+
// T+1000ms: Hedge #1 sent (if primary not complete)
487
+
// T+2000ms: Hedge #2 sent (if neither complete)
488
+
// First successful response wins, others cancelled
489
+
awaitapi.get('/api/data');
490
+
```
491
+
492
+
### Cancel-and-Retry Policy
493
+
494
+
Cancel-and-retry policy cancels slow requests and retries sequentially:
495
+
496
+
```js
497
+
constapi=createLuminara({
498
+
hedging: {
499
+
policy:'cancel-and-retry',
500
+
hedgeDelay:1500, // Wait 1.5s before cancelling
501
+
maxHedges:2// Up to 2 hedge attempts
502
+
}
503
+
});
504
+
505
+
// Timeline:
506
+
// T+0ms: Primary request sent
507
+
// T+1500ms: Cancel primary, send hedge #1
508
+
// T+3000ms: Cancel hedge #1, send hedge #2
509
+
// Only one request active at a time
510
+
awaitapi.get('/api/data');
511
+
```
512
+
513
+
### Exponential Backoff & Jitter
514
+
515
+
Increase hedge delays exponentially with randomization to prevent thundering herd:
0 commit comments