---
title: erl
summary: Package erl provides Edge Rate Limiting functionality.
url: https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/
---

**Kind:** Module  
**Package:** compute-sdk-go v1.11.0  
**Path:** `github.com/fastly/compute-sdk-go/erl`

Package erl provides Edge Rate Limiting functionality.

This package includes a [RateCounter](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.RateCounter/) type that can be used to
increment an event counter, and to examine the rate of events per
second within a POP over 1, 10, and 60 second windows.  It can also
estimate the number of events seen over the past minute within a POP
in 10 second buckets.

The [PenaltyBox](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.PenaltyBox/) type can be used to track entries that should be
penalized for a certain amount of time.

The [RateLimiter](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.RateLimiter/) type combines a rate counter and a penalty box to
determine whether a given entry should be rate limited based on
whether it exceeds a maximum threshold of events per second over a
given rate window.  Most users can simply use [RateLimiter.CheckRate](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.RateLimiter/#method-CheckRate)
rather than methods on [RateCounter](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.RateCounter/) and [PenaltyBox](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.PenaltyBox/).

Rate counters and penalty boxes are combined and synchronized within
a POP.  However, Edge Rate Limiting is not intended to compute counts
or rates with high precision and may under count by up to 10%.

Both rate counters and penalty boxes have a fixed capacity for
entries.  Once a rate counter is full, each new entry evicts the
entry that was least recently incremented.  Once a penalty box is
full, each new entry will evict the entry with the shortest remaining
time-to-live (TTL).

## Structs

| Name | Summary |
| --- | --- |
| [PenaltyBox](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.PenaltyBox/) | PenaltyBox is a type that allows entries to be penalized for a given number of minutes in the future. |
| [Policy](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.Policy/) | Policy contains the rules for applying a [RateLimiter](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.RateLimiter/). |
| [RateCounter](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.RateCounter/) | RateCounter is a named counter that can be incremented and queried. |
| [RateLimiter](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.RateLimiter/) | RateLimiter combines a [RateCounter](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.RateCounter/) and a [PenaltyBox](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.PenaltyBox/) to provide an easy way to check whether a given entry should be rate limited given a rate window and upper limit. |

## Type aliases

| Name | Summary |
| --- | --- |
| [CounterDuration](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/type.CounterDuration/) | CounterDuration indicates the estimated number of events in this duration in the current POP.  Counts are divided into 10 second buckets, and each bucket represents the estimated number of requests received up to and including that 10 second window. |
| [RateWindow](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/type.RateWindow/) | RateWindow indicates the rate of events per second in the current POP over one of a few predefined time windows.  See [RateWindow1s], [RateWindow10s], and [RateWindow60s]. |

## Functions

| Name | Summary |
| --- | --- |
| [NewRateLimiter](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/fn.NewRateLimiter/) | NewRateLimiter creates a new rate limiter. |
| [OpenPenaltyBox](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/fn.OpenPenaltyBox/) | OpenPenaltyBox opens a penalty box with the given name, creating it if it doesn't already exist.  The penalty box name may be up to 64 characters long.  Entry names in this penalty box are also limited to 64 characters. |
| [OpenRateCounter](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/fn.OpenRateCounter/) | OpenRateCounter opens a rate counter with the given name, creating it if it doesn't already exist.  The rate counter name may be up to 64 characters long.  Entry names in this counter are also limited to 64 characters. |

## Variables

### CounterDuration10s

**Type:** `fastly.CounterDuration`  
**Default:** `fastly.CounterDuration10s`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L67

CounterDuration10s indicates the estimated number of events in
the most recent 10 second bucket.

### CounterDuration20s

**Type:** `fastly.CounterDuration`  
**Default:** `fastly.CounterDuration20s`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L71

CounterDuration20s indicates the estimated number of events in
the most recent two 10 second buckets.

### CounterDuration30s

**Type:** `fastly.CounterDuration`  
**Default:** `fastly.CounterDuration30s`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L75

CounterDuration30s indicates the estimated number of events in
the most recent three 10 second buckets.

### CounterDuration40s

**Type:** `fastly.CounterDuration`  
**Default:** `fastly.CounterDuration40s`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L78

CounterDuration40s indicates the estimated number of events in
the most recent four 10 second buckets.

### CounterDuration50s

**Type:** `fastly.CounterDuration`  
**Default:** `fastly.CounterDuration50s`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L82

CounterDuration50s indicates the estimated number of events in
the most recent five 10 second buckets.

### CounterDuration60s

**Type:** `fastly.CounterDuration`  
**Default:** `fastly.CounterDuration60s`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L86

CounterDuration60s indicates the estimated number of events in
the most recent six 10 second buckets.

### ErrInvalidArgument

**Type:** `error`  
**Default:** `errors.New("invalid argument")`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L44

ErrInvalidArgument indicates that an invalid argument was passed
to one of the edge rate limiter methods.

Most functions and methods have limited ranges for their
parameters.  See the documentation for each call for more
details.

### ErrUnexpected

**Type:** `error`  
**Default:** `errors.New("unexpected error")`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L47

ErrUnexpected indicates that an unexpected error occurred.

### RateWindow10s

**Type:** `fastly.RateWindow`  
**Default:** `fastly.RateWindow10s`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L57

RateWindow10s indicates the rate of events per second over the
past 10 seconds.

### RateWindow1s

**Type:** `fastly.RateWindow`  
**Default:** `fastly.RateWindow1s`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L53

RateWindow1s incidates the rate of events per second over the past
second.

### RateWindow60s

**Type:** `fastly.RateWindow`  
**Default:** `fastly.RateWindow60s`  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L61

RateWindow60s indicates the rate of events per second over the
past 60 seconds.
