Plan-Based Limiting

Define different rate limits for different user tiers (Free, Pro, Enterprise).

Halt makes it easy to implement multi-tenant rate limiting where each tenant has a specific plan.

Defining Plans

const PLANS = {
  FREE: {
    name: 'free',
    limit: 100,
    window: 3600,
    burst: 120
  },
  PRO: {
    name: 'pro',
    limit: 10000,
    window: 3600,
    burst: 12000
  },
  ENTERPRISE: {
    name: 'enterprise',
    limit: 100000,
    window: 3600,
    burst: 120000
  }
};

Dynamic Policy Selection

You can select the policy dynamically based on the user's subscription.

app.use(async (req, res, next) => {
  const user = req.user;
  const policy = PLANS[user.plan] || PLANS.FREE;
  
  const limiter = new RateLimiter({
    store,
    policy,
    keyPrefix: `plan:${user.plan}`
  });
  
  await haltMiddleware(limiter)(req, res, next);
});