Concepts

Keys

Keys define the subject being rate limited, from a user or API key to a tenant or route.

A key is the identity Trypema limits. Good keys make your policy meaningful.

What a key usually represents

  • a user id
  • an API key
  • an IP address
  • a tenant id
  • a route + subject combination such as tenant_42:/search

Local keys

The local provider accepts plain string slices such as "user_123". That makes it easy to apply limiting anywhere inside one process.

Redis and hybrid keys

Redis-backed providers use RedisKey, a validated key type. It must:

  • not be empty
  • be at most 255 bytes
  • not contain :

Those rules keep the Redis key layout predictable because Trypema uses : as part of its internal namespacing.

How to choose a good key

Choose the identity you actually want to protect:

  • limit a person: user_id
  • limit a customer account: tenant_id
  • limit a credential: api_key_id
  • limit a hotspot route separately: tenant_id:/expensive-endpoint

Practical advice

  • Keep keys stable over time.
  • Keep them narrow enough to protect the thing that matters.
  • Avoid mixing different policy scopes into one key unless that is the policy you want.

The provider changes how state is stored, not what a key means.