Scalability Optimization for Codat API Using Retry and Rate Limiting

Ensure API reliability and prevent quota exhaustion with a structured retry and rate-limiting policy for Codat’s Active Connected Companies (ACC)-based rate model.

Use Cases

  • Managing ACC-Based Rate Limits – Codat enforces request quotas using 1,000 × (1 + Number of ACCs) daily requests with a concurrency cap of 10 simultaneous requests per ACC. A rate limiter ensures that API calls adhere to these dynamic constraints.
  • Retry Mechanism for 429 Responses – Retry-After headers are provided but lack per-endpoint granularity, requiring automated exponential backoff with jitter for stability.
  • Distributed Retry Strategies – Sharded request queues ensure that each ACC’s API interactions are isolated, preventing quota exhaustion from a single high-volume integration.
  • Request Prioritization – Critical requests (e.g., payment processing) must bypass retry backlogs when system load is high, using weighted fair queuing (WFQ).

Step-by-Step Breakdown

  1. Rate Limiting for ACC-Based Quotas – Enforces request limits based on ACC-specific quotas, ensuring compliance with dynamic daily allowances.
  2. Exponential Backoff with Jitter – Implements a retry strategy that gradually increases delays while adding randomness to prevent synchronized retry storms.
  3. Priority-Based Request Handling – Uses a weighted queue to prioritize high-impact requests while delaying non-critical API calls.
  4. ACC-Aware Traffic Routing – Ensures that each ACC’s request flow is independently managed to avoid quota exhaustion from a single overloaded integration.

Concrete Example

The Problem:
A fintech platform integrates with Codat to pull real-time financial data from multiple ACCs. As the user base scales:

  • API quotas must be constantly recalculated based on connected companies.
  • Uncoordinated retries cause API throttling, as requests ignore Retry-After headers.
  • Critical requests (e.g., payments) get stuck in overloaded retry queues, leading to delays.

The Solution:
By implementing a retry and rate-limiting middleware, API interactions remain efficient and quota-compliant:

  • Rate limits are enforced per ACC to ensure even distribution of API consumption.
  • Exponential backoff with jitter stabilizes retry behavior, reducing congestion and failed requests.
  • Prioritization mechanisms allow urgent requests to be processed first, avoiding unnecessary delays.

Retry & Rate Limiting Flow YAML Configuration

yaml
name: CodatRetryAndRateLimitFlow

filter:
  url: "https://api.codat.io/*"

processors:
  RateLimiter:
    processor: Limiter
    parameters:
      - key: quota_id
        value: CodatACCQuota
      - key: limit
        value: dynamic  # Dynamically calculates based on 1000 × (1 + ACC count)
      - key: window
        value: 24h
      - key: strategy
        value: per_acc  # Ensures requests are tracked per Active Connected Company
      - key: concurrency_limit
        value: 10  # Maximum of 10 simultaneous requests per ACC

  RetryProcessor:
    processor: Retry
    parameters:
      - key: max_retries
        value: 5
      - key: backoff_strategy
        value: exponential_with_jitter
      - key: jitter_factor
        value: 0.2  # Introduces ±20% randomness to prevent synchronized retry storms
      - key: retry_on_status_codes
        value: [429, 500, 502, 503]
      - key: retry_after_header
        value: "Retry-After"
      - key: max_delay
        value: 30000  # 30 seconds max retry delay

  PriorityQueue:
    processor: WeightedQueue
    parameters:
      - key: priority_mapping
        value:
          "payment_processing": 1.0
          "financial_reports": 0.8
          "background_sync": 0.5
      - key: strategy
        value: weighted_fair_queuing  # Ensures high-priority tasks are processed first

flow:
  request:
    - from:
        stream:
          name: globalStream
          at: start
      to:
        processor:
          name: RateLimiter

    - from:
        processor:
          name: RateLimiter
          condition: above_limit
      to:
        processor:
          name: RetryProcessor

    - from:
        processor:
          name: RateLimiter
          condition: below_limit
      to:
        processor:
          name: PriorityQueue

    - from:
        processor:
          name: PriorityQueue
      to:
        stream:
          name: globalStream
          at: end

  response:
    - from:
        processor:
          name: RetryProcessor
      to:
        stream:
          name: globalStream
          at: end
          size

Final Thoughts

By integrating rate limiting per ACC, exponential backoff with jitter, and priority-based queuing, API consumption remains scalable, stable, and responsive. This approach ensures efficient request distribution, prevents synchronized retry storms, and optimizes critical API workflows within Codat’s dynamic rate limit constraints.

About Lunar.dev:

Lunar.dev is your go to solution for Egress API controls and API consumption management at scale.
With Lunar.dev, engineering teams of any size gain instant unified controls to effortlessly manage, orchestrate, and scale API egress traffic across environments— all without the need for code changes.
Lunar.dev is agnostic to any API provider and enables full egress traffic observability, real-time controls for cost spikes or issues in production, all through an egress proxy, an SDK installation, and a user-friendly UI management layer.
Lunar.dev offers solutions for quota management across environments, prioritizing API calls, centralizing API credentials management, and mitigating rate limit issues.

By clicking “Accept”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information.