Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Stopping Chat Spam on Netlify with a Simple Rate‑Limit

Описание и применение

Простой способ остановить спам в публичном чате на Netlify: храните счётчик в Postgres, проверяйте его в Edge Function и возвращайте дружелюбный JSON‑ответ при превышении лимита.

Задача

Public chat endpoints can be flooded with bot messages, degrading user experience.

Результат

Spam traffic is reduced, backend load is protected, and users receive clear feedback, all without additional SaaS costs.

Рабочий процесс

  • Persist a lightweight counter in Postgres: store a row per IP or user token with timestamp and hit count, resetting if older than a day.
  • Gate the request with a Netlify Edge Function: read the counter before the request reaches the main API, short‑circuit with 429 if threshold exceeded (e.g., 5 messages per minute).
  • Return a friendly JSON payload: {"error": "Rate limit exceeded – please wait a moment before sending another message."} to inform users and bots.

Доказательства

Persist a lightweight counter in Postgres. I store a row per IP address (or per user token) with a timestamp and a hit count.

Источник

Gate the request with a Netlify Edge Function. The Edge Function reads the counter before the request reaches my main API. If the count exceeds the threshold (e.g., 5 messages per minute), the function short‑circuits and returns a 429 response.

Источник

Give a friendly “slow down” message. Instead of a generic error, I return a short JSON payload: { "error": "Rate limit exceeded – please wait a moment before sending another message." }

Источник

  • Дата записи: 2026-10-16T13:56:17.404Z