NOTE: this is still a draft, so it's subject to changes. This alert will be removed as soon as final version will be available

⚑@hsuite/throttler-types - Rate Limiting Type Definitions

⚑ Comprehensive TypeScript type definitions for HSuite Rate Limiting ecosystem with flexible storage backends

Enterprise-grade type definitions and interfaces providing a robust foundation for implementing rate limiting functionality across NestJS applications with support for Redis, in-memory storage, and dynamic configuration patterns.


πŸ“š Table of Contents


✨ Quick Start

Installation

npm install @hsuite/throttler-types

Basic Setup

NestJS Integration


πŸ—οΈ Architecture

Core Component Areas

⚑ Rate Limiting Foundation

  • Storage Backends - Redis and in-memory storage options for scalability

  • Configuration Management - Flexible settings for TTL, limits, and storage

  • Factory Patterns - Dynamic configuration with dependency injection

  • Type Safety - Comprehensive TypeScript interfaces and validation

🏭 Factory Pattern Integration

  • Options Factory - Interface for dynamic configuration creation

  • Async Configuration - Support for runtime configuration loading

  • Dependency Injection - Clean integration with NestJS DI system

  • Environment Flexibility - Different configurations for various environments

πŸ”„ Storage Backend Support

  • Redis Storage - Distributed storage for scalable rate limiting

  • In-Memory Storage - Local storage for simple deployments

  • Configuration Options - Complete Redis client configuration support

  • Fallback Mechanisms - Graceful degradation and error handling

πŸ›‘οΈ Enterprise Features

  • Multi-Tenant Support - Tenant-specific rate limiting configurations

  • Tier-Based Limiting - Different limits based on user tiers

  • Dynamic Adjustment - Runtime configuration changes

  • Monitoring Integration - Type-safe monitoring and metrics

Module Structure


πŸ”§ API Reference

Core Interface Types

Storage Backend Types

IThrottler.IStorage

  • Purpose: Available storage options for persisting throttling data

  • Values: REDIS, DEFAULT

  • Usage: Storage backend selection for rate limiting data

Configuration Types

IThrottler.IOptions

  • Purpose: Complete throttler configuration interface

  • Properties: enabled, settings, storage, redis

  • Usage: Main configuration object for throttler setup

IThrottler.IOptionsFactory

  • Purpose: Factory interface for dynamic configuration

  • Methods: createThrottlerOptions()

  • Usage: Runtime configuration generation

Module Configuration Types

IThrottler.IModuleAsyncOptions

  • Purpose: Async module configuration for throttler initialization

  • Properties: useClass, useFactory, inject

  • Usage: NestJS module async configuration

Storage Selection Guidelines

Storage Type
Use Case
Scalability
Performance
Complexity

Redis

Production, Distributed

High

High

Medium

Default

Development, Single Instance

Low

Very High

Low

Configuration Parameters

Parameter
Type
Description
Default
Required

enabled

boolean

Global throttling toggle

-

Yes

settings.ttl

number

Time window (seconds)

-

Yes

settings.limit

number

Max requests per window

-

Yes

storage

IStorage

Storage backend type

-

Yes

redis

RedisClientOptions

Redis configuration

-

Yes


πŸ“– Guides

Rate Limiting Setup Guide

Complete guide to setting up rate limiting with different storage backends. Comprehensive setup instructions covering Redis and in-memory storage configuration, TTL and limit settings, environment-specific configurations, and performance optimization for enterprise-scale rate limiting systems.

Factory Pattern Guide

Learn how to implement dynamic configuration with factory patterns. Advanced implementation guide covering factory pattern integration, dynamic configuration loading, environment-based config selection, tenant-specific overrides, and runtime configuration validation for flexible throttling systems.

Multi-Tenant Configuration Guide

Set up tenant-specific and tier-based rate limiting configurations. Detailed guide for implementing multi-tenant rate limiting with tier-based limits, tenant isolation, configuration inheritance, custom Redis key prefixes, and enterprise-grade tenant management.

Production Deployment Guide

Best practices for deploying rate limiting in production environments. Comprehensive deployment guide covering Redis clustering, performance monitoring, error handling, failover strategies, and production optimization for high-availability rate limiting systems.


🎯 Examples

Storage Backend Configuration

Factory Pattern Implementation

Multi-Tenant Rate Limiting

Advanced Factory Patterns

Type-Safe Configuration Validation


πŸ”— Integration

Required Dependencies

Module Integration

Documentation Generation

Integration with HSuite Ecosystem

Use Cases

🌐 API Rate Limiting

  • RESTful API endpoint protection

  • GraphQL query rate limiting

  • WebSocket connection throttling

  • File upload rate control

πŸ›‘οΈ DDoS Protection

  • Request flooding prevention

  • IP-based rate limiting

  • Burst request handling

  • Adaptive rate limiting

πŸ”§ Resource Usage Control

  • Database connection throttling

  • CPU-intensive operation limiting

  • Memory usage protection

  • Third-party API call limiting

🏒 Multi-Tenant Applications

  • Tenant-specific rate limits

  • Tier-based throttling

  • Usage quota enforcement

  • Fair resource distribution


⚑ Enterprise Rate Limiting: Comprehensive TypeScript definitions with flexible storage backends and dynamic configuration support.

🏭 Factory Pattern Integration: Clean dependency injection with async configuration capabilities for complex deployment scenarios.

πŸ”„ Multi-Storage Support: Redis for distributed systems and in-memory for simple deployments with seamless switching.


Built with ❀️ by the HSuite Team Copyright © 2025 HSuite. All rights reserved.

Last updated