diff --git a/.env.example b/.env.example
index d32b9be0..23a79a31 100644
--- a/.env.example
+++ b/.env.example
@@ -7,7 +7,13 @@ SESSION_TTL_SECONDS=3600
# Choose credentials locally. File paths contain no secret values.
DATABASE_URL_FILE=/run/secrets/database_url
# Optional on 3, required use on 4 in lab2; Redis OR Valkey:
-SESSION_STORE=postgres
+SESSION_STORE=valkey
CACHE_URL_FILE=/run/secrets/cache_url
+SESSION_CACHE_MAX_TTL_SECONDS=60
API_REPLICAS=2
IDEMPOTENCY_TTL_SECONDS=86400
+DB_MAX_CONNS=10
+API_CPUS=1.0
+API_MEMORY=256M
+SHUTDOWN_DRAIN_MS=3000
+MESSAGE_WRITE_PATH=oneshot
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..b2b5733f
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,25 @@
+# syntax=docker/dockerfile:1
+
+FROM golang:1.23.4-alpine3.21 AS build
+WORKDIR /src
+
+COPY src/go.mod src/go.sum ./
+RUN go mod download
+
+COPY src/ ./
+ENV CGO_ENABLED=0
+RUN go build -trimpath -ldflags="-s -w" -o /out/server ./cmd/server
+
+FROM alpine:3.21.2 AS runtime
+RUN addgroup -S app && adduser -S -G app app
+WORKDIR /app
+COPY --from=build /out/server /app/server
+ARG APP_BUILD=dev
+ENV APP_BUILD=$APP_BUILD
+LABEL org.opencontainers.image.revision=$APP_BUILD
+USER app
+EXPOSE 8080
+ENV APP_HOST=0.0.0.0 APP_PORT=8080
+HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \
+ CMD wget -q -O /dev/null http://127.0.0.1:8080/health/ready || exit 1
+ENTRYPOINT ["/app/server"]
diff --git a/Makefile b/Makefile
index 5d86d171..f239b976 100644
--- a/Makefile
+++ b/Makefile
@@ -4,10 +4,12 @@ CA_FILE ?=
ACTION_SCRIPT ?=
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
-.PHONY: help check validate test load test-persistence test-failover
+.PHONY: help check validate test load test-persistence test-failover \
+ secrets up down ps restore test-student failover-series rolling-update track1 track1-report
help:
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
+ @echo "up/down/ps/restore: stack; test-student, failover-series, rolling-update: level 4; track1: level 5"
check:
$(PYTHON) scripts/check_contract.py
@@ -28,3 +30,35 @@ test-persistence:
test-failover:
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable stop-one hook"; exit 2)
$(PYTHON) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
+
+secrets:
+ $(PYTHON) scripts/init_secrets.py
+
+up: secrets
+ docker compose up -d --build --wait
+
+down:
+ docker compose stop
+
+ps:
+ docker compose ps -a
+
+restore:
+ docker compose up -d --wait
+
+test-student:
+ $(PYTHON) student-tests/run_tests.py --base-url "$(BASE_URL)" --json evidence/student-tests.json
+
+failover-series:
+ $(PYTHON) scripts/failover_series.py --mode stop --output evidence/failover-stop.json
+ $(PYTHON) scripts/failover_series.py --mode kill --output evidence/failover-kill.json
+
+rolling-update:
+ $(PYTHON) scripts/rolling_update.py --output evidence/rolling-update.json
+
+track1:
+ $(PYTHON) scripts/track1/run_track1.py --series fixed --repeat 3
+ $(PYTHON) scripts/track1/run_track1.py --series growth --repeat 3
+
+track1-report:
+ $(PYTHON) scripts/track1/report_track1.py
diff --git a/REPORT.md b/REPORT.md
index c2679005..ad73e002 100644
--- a/REPORT.md
+++ b/REPORT.md
@@ -1,37 +1,286 @@
# Отчёт — лабораторная 3
-- Автор, группа: TODO
-- Целевая оценка; выбранный трек 5, если нужен: TODO
-- Commit/PR: TODO после публикации
-- Использованные источники, библиотеки и помощь ИИ: TODO
+- Автор, группа: Кораблев Петр, БВТ2304
+- Целевая оценка: 5 (уровень 3 + уровень 4 + трек 1 «Цена масштабирования»)
+- Commit/PR: ветка `solution/BVT2304-korablev`
+- Использованные источники, библиотеки и помощь ИИ: Go 1.23.4, net/http, pgx/v5 5.7.2 (pgxpool), go-redis/v9 9.7.0, golang.org/x/crypto (Argon2id), google/uuid 1.6.0, `log/slog`. Образы: PostgreSQL 17.2-alpine3.21, Valkey 8.0.2-alpine3.21, HAProxy 3.0.5-alpine, golang:1.23.4-alpine3.21 → alpine:3.21.2, k6 0.54.0 (только трек 1). Документация: Compose services/deploy, HAProxy configuration manual (resolvers, http-check, retry-on), PostgreSQL docs (INSERT … ON CONFLICT, data-modifying CTE). Помощь ИИ использовалась для создания отчета.
+
## Запуск из чистого clone
-TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных.
+Prerequisites:
+
+- Docker 29.1.3 (Docker Desktop для Windows + WSL2) с Compose v2
+- Python 3.9+ (тесты и генерация секретов)
+- Git; make по желанию (на Windows команды можно запускать напрямую через `py -3 ...`)
+- Go локально **не нужен**: приложение собирается внутри Docker
+
+Шаги:
+
+1. Клонировать репозиторий и создать локальные секреты и `.env`:
+
+ ```sh
+ python3 scripts/init_secrets.py # = make secrets
+ ```
+
+ Скрипт генерирует случайные пароли в `secrets/` (`pg_password`, `database_url`, `cache_url`, `valkey_auth.conf`) и копирует `.env.example` → `.env`. Обе папки исключены из Git и из Docker build context. Пароли передаются контейнерам как Compose secrets (`/run/secrets/...`), в `.env` секретов нет:
+
+ ```
+ APP_PORT=8080
+ SESSION_STORE=valkey
+ SESSION_TTL_SECONDS=3600
+ SESSION_CACHE_MAX_TTL_SECONDS=60
+ API_REPLICAS=2
+ IDEMPOTENCY_TTL_SECONDS=86400
+ DB_MAX_CONNS=10 # пул на одну реплику
+ API_CPUS=1.0 # лимиты одной реплики
+ API_MEMORY=256M
+ SHUTDOWN_DRAIN_MS=3000 # пауза drain при SIGTERM
+ MESSAGE_WRITE_PATH=oneshot # tx — только для A/B трека 1
+ ```
+
+2. Запустить стенд:
+
+ ```sh
+ docker compose up -d --build --wait # = make up
+ ```
+
+ Compose:
+ - `postgres` — 17.2-alpine3.21, volume `pgdata`, только внутренняя сеть `data`, 2 CPU / 1 GiB.
+ - `valkey` — 8.0.2-alpine3.21, кэш сессий с паролем из secret, сеть `data`, 0.5 CPU / 128 MiB.
+ - `migrate` — тот же образ с командой `migrate`: однократно применяет миграции под advisory lock и завершается.
+ - `api` — 2 реплики (`deploy.replicas: ${API_REPLICAS}`), без `ports` и без `container_name`, 1 CPU / 256 MiB каждая.
+ - `lb` — HAProxy 3.0.5-alpine, единственный опубликованный порт `127.0.0.1:8080` (и `[::1]:8080`).
+
+3. Дождаться готовности:
+
+ ```sh
+ docker compose ps
+ ```
+
+ Ожидаемо: postgres, valkey, api-1, api-2, lb — healthy, migrate — Exited (0).
+
+4. Прогнать тесты:
+
+ ```sh
+ make check
+ make test
+ make test-persistence ACTION_SCRIPT=scripts/restart.sh
+ make test-failover ACTION_SCRIPT=scripts/stop-one.sh
+ docker compose up -d --wait # вернуть остановленную реплику (= make restore)
+ make test-student # собственные тесты
+ ```
+
+ **Windows:** Python не запускает `.sh` через `subprocess`, поэтому рядом лежат `scripts/stop-one.cmd` и `scripts/restart.cmd` с теми же командами. Перед тестами нужно выполнить `$env:PYTHONUTF8="1"`, иначе Python читает `contracts/openapi.json` в cp1251. Пошаговый сценарий для защиты — в `ЗАЩИТА.txt`.
+
+5. Остановить:
+
+ ```sh
+ docker compose stop # = make down
+ ```
+
+ **Данные сохраняются** в named volume `mtusi-lab3_pgdata`.
+
+ **Намеренное удаление:**
+
+ ```sh
+ docker compose down -v
+ ```
## Архитектура и решения
-TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab2, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации.
+- **Топология.** Клиент → HAProxy (LB, порт 8080) → 2 API-реплики (сеть `app`, порт 8080 только внутри) → общие PostgreSQL и Valkey (сеть `data`). LB не видит БД; пароль БД получают только `api` и `migrate`.
+- **Балансировка.** HAProxy `roundrobin`, без sticky. Healthcheck `GET /health/ready` каждую 1 с (`inter 1s fastinter 500ms fall 2 rise 2`, `timeout check 500ms`). Отказ реплики обнаруживается **не позже чем за ~2,5 с**.
+- **Динамическое обнаружение реплик.** HAProxy резолвит имя `api` через Docker DNS `127.0.0.11` (`server-template api 8 api:8080`, `hold valid 2s`). Масштабирование `--scale api=N` не требует правки конфига.
+- **Повторы на LB.** `retry-on conn-failure` + `option redispatch`: запрос пересылается на другую реплику, только если соединение не установилось. POST, который мог дойти до реплики, LB не повторяет: это делает клиент с тем же `Idempotency-Key`.
+- **X-Instance-Id.** Hostname контейнера (короткий ID Docker) или `INSTANCE_ID`. Ставится самым внешним middleware (`instanceIDMiddleware` в `src/internal/api/middleware.go`), поэтому есть в каждом ответе API, включая ошибки и health. Стабилен в жизни процесса. Его же использует `stop-one` для поиска контейнера.
+- **Идемпотентность.** Таблица `message_idempotency` (миграция `0002`), PK `(user_id, chat_id, idem_key)` = область «пользователь + POST + путь чата + ключ». `request_hash` — SHA-256 канонического JSON тела (порядок ключей и пробелы не влияют), TTL 24 ч с фоновой очисткой. Логика (`store.AddMessageOneShot`) — **один SQL-оператор** с data-modifying CTE:
+ 1. проверить членство в чате;
+ 2. `INSERT` ключа `ON CONFLICT DO UPDATE … WHERE просрочен` (перезахват только просроченного ключа);
+ 3. `INSERT` сообщения, только если ключ захвачен этим запросом.
+
+ Ключ и сообщение пишутся **атомарно**: при сбое не остаётся ни того, ни другого, и клиент может безопасно повторить запрос. При конкурентном повторе через другую реплику PostgreSQL заставляет второй запрос ждать на PK. После коммита первого второй отдельным оператором читает сохранённое сообщение: тот же `201` и тот же Message. Другое тело — `409`.
+- **Порядок проверок.** Токен (401) → доступ к чату (404) → валидация (400). Посторонний с невалидным телом получает 404, а не 400.
+- **Graceful shutdown.** По SIGTERM `/health/ready` сразу отдаёт 503, процесс ещё 3 с обслуживает запросы (это больше максимального времени обнаружения отказа), затем отключает keep-alive и выполняет `Shutdown` с бюджетом 5 с. `stop_grace_period: 15s`.
+- **Таймауты согласованы.** Контекст запроса в приложении 8 с < `timeout server` HAProxy 10 с; в PostgreSQL `statement_timeout` 5 с, `lock_timeout` 2 с.
+- **Источник истины — PostgreSQL.** Сессии хранятся в PostgreSQL (SHA-256 токена), Valkey — кэш перед ним (не более 60 с). При отказе Valkey проверка сессии уходит в PostgreSQL; logout в этом случае отвечает 503, чтобы в кэше не осталась отозванная сессия.
+- **Пароли.** Argon2id (перенесено из lab2).
+- **Миграции.** Версионируемые SQL в `src/internal/db/migrations`, отдельный сервис `migrate`, `pg_advisory_lock`, API ждёт `service_completed_successfully`. Миграция `0002` аддитивная, поэтому совместима со старой версией кода при rolling update.
+- **CPU/RAM-лимиты** на всех сервисах (`deploy.resources.limits`), включая `migrate` и `lb`.
+- **API не публикуют порты**: опубликован только LB.
## Доказательства критериев
-| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства |
-| --- | --- | --- | --- |
-| Публичный smoke | make test | TODO | TODO |
-| Остальные пункты уровня 3 | TODO | TODO | TODO |
-| Все пункты уровня 4, если заявлен | TODO | TODO | TODO |
-| Выбранный трек 5, если заявлен | TODO | TODO | TODO |
+### Уровень 3
-TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены.
+| Критерий | Команда/сценарий | Результат |
+| --- | --- | --- |
+| Структура и контракт | `make check`, `make validate` | `PASS` / `PASS` (`evidence/check-smoke.txt`, `evidence/validate.txt`) |
+| Публичный smoke | `make test` | `PASS: lab3 public API scenario` |
+| ≥2 API-реплики | `docker compose ps` | `mtusi-lab3-api-N` ×2 healthy, `lb` healthy, `migrate` Exited (0) (`evidence/infra.txt`) |
+| Разные реплики обслуживают одну сессию | `python scripts/demo/instances.py`, student-test `no stickiness` | 30 запросов одним токеном: 15 / 15 по двум `X-Instance-Id`, без повторного входа |
+| LB — единая точка входа | `docker inspect … PortBindings` | порт только у `lb`; у api/postgres/valkey `{}` |
+| Остановка одной реплики | `make test-failover ACTION_SCRIPT=scripts/stop-one.sh` | 7/7 PASS, `failed_attempts: 0`, `first_recovery_seconds` 3,76–3,91 |
+| Идемпотентность | smoke + `python scripts/demo/idempotency.py` | повтор → тот же Message, другое тело → `409`, без ключа → `400` |
+| make test-persistence | `make test-persistence ACTION_SCRIPT=scripts/restart.sh` | PASS; `StartedAt` всех контейнеров до и после разный (`evidence/persistence.txt`) |
+
+### Уровень 4
+
+| Критерий | Команда/сценарий | Результат |
+| --- | --- | --- |
+| LB исключает недоступный backend, SIGTERM | `python scripts/failover_series.py --mode stop` | остановленная реплика последний раз ответила через 1,4–1,6 с; **0 ошибок** при ~800 RPS |
+| Последовательная остановка каждой реплики | `make test-failover` по обеим репликам + `failover_series.py` (stop и kill) | обе реплики остановлены по очереди с восстановлением; все PASS |
+| Параллельная идемпотентность | `make test-student` (`concurrent replay`) | 24 параллельных запроса через 2 реплики → **1 сообщение** |
+| CPU/RAM-лимиты | `docker inspect … NanoCpus/Memory` | на всех сервисах (`evidence/infra.txt`) |
+| API не публикуют порты | `docker compose ps` | у api только `8080/tcp` внутри сети, порт на хосте только у lb |
+| Нет container_name | `grep container_name compose.yaml` | пусто; масштабирование `--scale api=N` работает |
+| Rolling update под нагрузкой | `python scripts/rolling_update.py` | **0 ошибок**, 812 RPS во время замены, обе реплики на новом образе |
+| Миграции однократно и совместимо | сервис `migrate` + повторный `docker compose run --rm migrate` в rolling update | `Exited (0)`, `migrations up to date`; `0002` только добавляет таблицу |
+
+### Метрики failover
+
+Публичный тест, 7 прогонов. Остановлены обе реплики: api-8 (прогоны 1–6) и api-10 (прогон 7, после сдвига round-robin одним запросом):
+
+```json
+{"observed_instances_before": 2, "successful_writes": 136, "failed_attempts": 0, "first_recovery_seconds": 3.888}
+{"observed_instances_before": 2, "successful_writes": 137, "failed_attempts": 0, "first_recovery_seconds": 3.869}
+{"observed_instances_before": 2, "successful_writes": 136, "failed_attempts": 0, "first_recovery_seconds": 3.763}
+{"observed_instances_before": 2, "successful_writes": 138, "failed_attempts": 0, "first_recovery_seconds": 3.842}
+{"observed_instances_before": 2, "successful_writes": 139, "failed_attempts": 0, "first_recovery_seconds": 3.913}
+{"observed_instances_before": 2, "successful_writes": 137, "failed_attempts": 0, "first_recovery_seconds": 3.806}
+{"observed_instances_before": 2, "successful_writes": 139, "failed_attempts": 0, "first_recovery_seconds": 3.905}
+```
+
+**Интерпретация:**
+- `observed_instances_before: 2` — балансировка работала до отказа, sticky нет.
+- `failed_attempts: 0` — ни один запрос не получил ошибку: реплика при SIGTERM сначала выходит из ротации (readiness 503, HAProxy исключает её за ≤2,5 с) и только потом завершается (drain 3 с).
+- `first_recovery_seconds: ~3,8` — тест считает восстановление от старта hook до первой успешной записи **после** завершения hook. Почти всё это время уходит на сам `docker stop` с 3-секундным drain; запись при этом не прерывалась. Требование lab3 — ≤10 с.
+- После теста `docker ps -a` показывает именно этот контейнер в состоянии `Exited (0)` (`evidence/failover.txt`).
+
+### Отказ каждой реплики под нагрузкой
+
+`scripts/failover_series.py`: 8 потоков closed-loop POST через LB, таймаут клиента 2 с. Неопределённый POST повторяется с **тем же** ключом, в конце вся история сверяется с подтверждёнными `201`.
+
+```json
+{"replica": "mtusi-lab3-api-10", "action": "docker stop", "errors": 0, "ok_rps_before": 802.0, "ok_rps_after": 805.1, "target_last_served_s": 1.57, "back_in_rotation_s": 5.87}
+{"replica": "mtusi-lab3-api-8", "action": "docker stop", "errors": 0, "ok_rps_before": 651.6, "ok_rps_after": 747.4, "target_last_served_s": 1.42, "back_in_rotation_s": 6.1}
+{"replica": "mtusi-lab3-api-10", "action": "docker kill", "errors": 4, "ok_rps_before": 704.2, "ok_rps_after": 582.1, "last_error_s": 0.1, "back_in_rotation_s": 6.1}
+{"replica": "mtusi-lab3-api-8", "action": "docker kill", "errors": 2, "ok_rps_before": 729.6, "ok_rps_after": 618.4, "last_error_s": 0.12, "back_in_rotation_s": 5.89}
+```
+
+Проверка данных: stop — `stored 38100 = confirmed 38100, lost 0, duplicates 0`; kill — `stored 32533 = confirmed 32533, lost 0, duplicates 0`.
+
+**Интерпретация:** при штатной остановке (SIGTERM) ошибок нет совсем. При crash (`docker kill`, без SIGTERM) 2–4 запроса, которые были в работе у убитого процесса, получили `502` от LB в первые 0,1 с. Клиент повторил их с тем же ключом, поэтому нет ни потерь, ни дублей. В первую секунду после kill p99 ≈ 1 с — это `timeout connect` к исчезнувшему адресу, после которого срабатывает redispatch. Восстановленная реплика возвращается в ротацию через ~6 с после `docker start` (старт, затем 2 успешные проверки).
+
+### Метрики rolling update
+
+`scripts/rolling_update.py`: сборка нового образа → миграции **один раз** → для каждой старой реплики: поднять новую (surge +1) → дождаться healthy и появления в ротации → `docker stop` старой (drain) → удалить.
+
+```json
+{
+ "before_rollout_5s": {"ok_rps": 789.2, "errors": 0, "p50_ms": 6.8, "p95_ms": 28.0, "p99_ms": 31.8},
+ "during_rollout": {"seconds": 27.61, "ok": 22423, "errors": 0, "ok_rps": 812.1, "p50_ms": 7.2, "p95_ms": 26.7, "p99_ms": 31.2},
+ "after_rollout_5s": {"ok_rps": 804.6, "errors": 0, "p50_ms": 6.7, "p95_ms": 29.1, "p99_ms": 31.8},
+ "client_retries": 0,
+ "all_new_label": true,
+ "data_check": {"stored_messages": 30400, "confirmed_201": 30400, "lost_confirmed": 0, "duplicate_texts": 0}
+}
+```
+
+**Интерпретация:** обе реплики заменены на образ `final-rollout` без единой ошибки и без retry. Пропускная способность во время замены не просела: в каждый момент работают ≥2 реплики, старая уходит только после того, как новая принимает трафик.
+
+### Параллельная идемпотентность
+
+```
+PASS concurrent replay of one key through different replicas -> exactly one message - 24 parallel requests via 2 replicas -> 1 message
+PASS replay is semantic: JSON key order/whitespace does not matter; other body -> 409
+PASS key scope = user + chat: same key is independent for other user / other chat
+PASS replay re-checks the session and chat access
+8/8 passed
+```
+
+24 потока одновременно отправили POST с **одним** `Idempotency-Key` и **одинаковым** телом через обе реплики. Все получили `201` с одним и тем же Message, в истории **одно** сообщение. Тот же ключ с другим телом даёт `409` и не перезаписывает сохранённый результат.
## Эксперименты и отказы
-TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения.
-
-| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных |
+| Воздействие | Ожидаем | Наблюдали | Восстановление / потери |
| --- | --- | --- | --- |
-| TODO | TODO | TODO | TODO |
+| `docker stop` api-10, затем api-8, под нагрузкой | Вторая продолжает, drain без ошибок | 0 ошибок, RPS 802→805 и 652→747 | без перерыва; возврат в ротацию ~6 с; потерь 0 |
+| `docker kill` api-10, затем api-8, под нагрузкой | Ошибки только у запросов «в полёте» | 4 и 2 ответа `502` в первые 0,1 с | клиент повторил с тем же ключом; потерь 0, дублей 0 |
+| Публичный `test-failover`, 7 прогонов | ≤10 с, нет потерь | 7/7 PASS, 0 failed_attempts | ~3,8 с (длительность `docker stop`) |
+| Перезапуск всего стека с volumes | Данные и сессия выживают | PASS persistence | данные и прежний токен на месте |
+| Параллельные POST с одним ключом | Одно сообщение | 24 → 1 | — |
+| Rolling update под нагрузкой | Без ошибок | 0 ошибок, 812 RPS | замена ~28 с; потерь 0 |
+
+## Трек 1. Цена масштабирования
+
+**Гипотеза.** При фиксированном суммарном CPU/RAM больше реплик — не быстрее. При росте числа реплик пропускная способность упрётся в единственный PostgreSQL (2 CPU), а именно в фиксацию транзакций. Поднять потолок можно, уменьшив работу БД на запрос, а не добавляя реплики.
+
+**Методика** (`scripts/track1/run_track1.py`, сценарий `infra/k6/track1.js`):
+- **Генератор.** k6 0.54 в контейнере внутри сети стенда (`lb:8080`) с лимитом 4 CPU. Контроль: при 8 CPU у k6 получилось 3516 RPS против 3474, значит k6 не ограничивает.
+- **Профиль.** Closed model: 128 VU без пауз, 70% `POST /messages` (уникальный ключ), 30% `GET /messages?limit=20`. 32 синтетических пользователя, у каждого свой чат.
+- **Измерение.** Прогрев 10 с, замер 30 с, **3 повтора**, конфигурации чередуются (A, B, C, A, B, C…).
+- **Метрики.** Параллельно снимаются `docker stats` (CPU и RAM по сервисам) и `pg_stat_activity` (активные backend и события ожидания).
+- **Фиксировано:** PostgreSQL 2 CPU / 1 GiB, LB 1 CPU.
+- **Стенд:** i7-14700KF, 64 GB RAM, Windows 11, Docker Desktop (WSL2).
+- **Данные:** сырые — `evidence/track1/raw/`, сводка — `evidence/track1/summary.md` и `results.json`, графики — `evidence/track1/*.svg`.
+
+**Серия 1. Фиксированный бюджет API** (2 CPU, 512 MiB, 20 соединений с БД на всех):
+
+| Раскладка | RPS, среднее (min–max) | p50 / p95 / p99, мс | CPU api / pg, % ядра |
+| --- | --- | --- | --- |
+| 1 × 2.0 CPU, пул 20 | **3636** (3272–3835) | 26,6 / 63,7 / 71,6 | 179 / 171 |
+| 2 × 1.0 CPU, пул 10 | 3537 (3519–3572) | 30,2 / 79,4 / 91,3 | 182 / 154 |
+| 4 × 0.5 CPU, пул 5 | 3110 (2985–3204) | 31,3 / 96,7 / 121,9 | 187 / 146 |
+
+
+
+При том же бюджете 4 мелкие реплики дают на 14% меньше RPS, а p95 у них в 1,5 раза выше. Маленькая CPU-квота чаще троттлит Go-рантайм, а пул из 5 соединений быстрее превращается в очередь. Реплики нужны ради отказоустойчивости, а не ради скорости.
+
+**Серия 2. Рост числа реплик** (по 1 CPU / 256 MiB / пул 10):
+
+| Реплик | RPS (min–max) | Прирост | CPU api (сумма) / pg | Активных backend PG | Главное ожидание PG |
+| --- | --- | --- | --- | --- | --- |
+| 1 | 2051 (2033–2065) | — | 95 / 82 | 5,6 | WALWriteLock 4,4 |
+| 2 | 3440 (3264–3564) | +68% | 188 / 161 | 9,3 | WALWriteLock 7,7 |
+| 4 | **3645** (3559–3740) | +6% | 198 из 400 / **187 из 200** | 28,4 | WALWriteLock 24,4 |
+| 8 | 3408 (3334–3494) | **−7%** | 185 из 800 / 180 | 48,3 | WALWriteLock 40,4 |
+
+
+
+**Saturation point ≈ 3,6k RPS, узкое место — PostgreSQL.**
+- С 1 до 2 реплик упиралась сама реплика API (95% CPU).
+- С 4 реплик API загружен наполовину, а PostgreSQL — на 187% из 200%. Очередь в нём растёт с числом соединений (9 → 28 → 48), ~85% из них ждут `WALWriteLock`, то есть фиксацию журнала при commit.
+- 8 реплик медленнее 4: больше соединений — длиннее очередь.
+- LB (~47% одного CPU) и Valkey (<10%) не ограничивают.
+
+**Подтверждённое улучшение: запись сообщения одним SQL-оператором.** Было (`tx`): 5 обращений к БД на сообщение — `SELECT` членства, `BEGIN`, `INSERT` ключа, `INSERT` сообщения, `COMMIT`. Стало (`oneshot`): 1 оператор с CTE. Гарантии те же (атомарность, ожидание конкурента на PK), durability не ослаблена: fsync и `synchronous_commit` не трогались. A/B на одном образе (`MESSAGE_WRITE_PATH`), по 3 повтора, вперемешку:
+
+| Конфигурация | tx: RPS, p95 | oneshot: RPS, p95 | Эффект |
+| --- | --- | --- | --- |
+| 2 × 1 CPU | 3390 (3374–3419), 80,0 мс | **4579** (4453–4681), 61,4 мс | **+35% RPS, −23% p95** |
+| 4 × 1 CPU | 3474 (3249–3600), 87,6 мс | **4301** (4241–4350), 79,0 мс | **+24% RPS, −10% p95** |
+
+
+
+Диапазоны min–max не пересекаются, поэтому эффект больше разброса между повторами. Saturation point сдвинулся с ~3,6k до ~4,6k RPS. Его природа не изменилась: при 4 репликах oneshot снова медленнее, чем при 2, потому что очередь на WAL растёт.
+
+**Выводы трека:**
+1. При фиксированных ресурсах больше реплик — не быстрее. Минимум 2 реплики нужны для отказоустойчивости.
+2. Реплики помогают, пока узкое место — CPU API (здесь до 2 реплик). Дальше упираемся в PostgreSQL (WAL commit).
+3. Поднять потолок можно, уменьшив работу БД на запрос: подтверждено, +24…35%. Следующие шаги — более мощная БД, ограничение суммарного пула или pgbouncer, реплики БД для чтения.
+
+**Ограничения измерения:**
+- Один хост: k6, LB, API и БД делят CPU и виртуальный диск WSL2. Переносить можно только относительные выводы, не абсолютные числа.
+- Closed model; open model (arrival rate) не исследовалась.
+- `docker stats` даёт средние с шагом ~2 с.
+- Отдельную серию с ростом CPU PostgreSQL я не проводил: вывод об узком месте основан на загрузке CPU (~93% лимита) и доминирующих ожиданиях WAL.
## Ограничения и следующие шаги
-TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза.
+- **SPOF:** LB (HAProxy), PostgreSQL и сам Docker-хост — единственные экземпляры. Падение LB делает сервис недоступным, падение PostgreSQL даёт 503. Это осознанное ограничение lab3: несколько API-процессов не делают БД или LB высокодоступными (это тема трека 2 «Отказ узла»).
+- **Crash реплики:** запросы, которые были в работе, получают `502` от LB (2–4 за отказ при ~700 RPS). Безопасно повторять только POST сообщения с ключом. Создание пользователя или чата вслепую повторять нельзя (контракт).
+- **Valkey без persistence:** это кэш, источник истины — PostgreSQL. При его рестарте сессии перечитываются из БД.
+- **Rolling update** сделан скриптом (в Compose нет встроенного rolling update). Миграции совместимы, пока они аддитивные. Для удаляющих или переименовывающих миграций нужен expand/contract в два релиза.
+- **Детерминированный round-robin:** публичный failover-тест после восстановления попадает в ту же реплику. Для второй реплики очередь сдвигалась одним дополнительным запросом к LB.
+- **Учебные упрощения:** `X-Instance-Id` раскрывает ID контейнера (в lab7 нужен случайный alias); HTTP без TLS; путь `tx` оставлен в коде только для воспроизводимости A/B трека 1.
diff --git a/compose.yaml b/compose.yaml
new file mode 100644
index 00000000..17abf156
--- /dev/null
+++ b/compose.yaml
@@ -0,0 +1,139 @@
+name: mtusi-lab3
+
+x-api-env: &api-env
+ APP_HOST: 0.0.0.0
+ APP_PORT: "8080"
+ APP_ENV: ${APP_ENV:-lab}
+ SESSION_STORE: ${SESSION_STORE:-valkey}
+ SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
+ SESSION_CACHE_MAX_TTL_SECONDS: ${SESSION_CACHE_MAX_TTL_SECONDS:-60}
+ IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
+ SHUTDOWN_DRAIN_MS: ${SHUTDOWN_DRAIN_MS:-3000}
+ DB_MAX_CONNS: ${DB_MAX_CONNS:-10}
+ MESSAGE_WRITE_PATH: ${MESSAGE_WRITE_PATH:-oneshot}
+ DATABASE_URL_FILE: /run/secrets/database_url
+ CACHE_URL_FILE: /run/secrets/cache_url
+
+services:
+ postgres:
+ image: postgres:17.2-alpine3.21
+ environment:
+ POSTGRES_DB: messenger
+ POSTGRES_USER: messenger
+ POSTGRES_PASSWORD_FILE: /run/secrets/pg_password
+ command: ["postgres", "-c", "max_connections=${PG_MAX_CONNECTIONS:-100}"]
+ secrets: [pg_password]
+ volumes:
+ - pgdata:/var/lib/postgresql/data
+ networks: [data]
+ shm_size: 256mb
+ healthcheck:
+ test: ["CMD-SHELL", "pg_isready -U messenger -d messenger -h 127.0.0.1"]
+ interval: 2s
+ timeout: 3s
+ retries: 30
+ deploy:
+ resources:
+ limits: {cpus: "${PG_CPUS:-2.0}", memory: "${PG_MEMORY:-1G}"}
+ stop_grace_period: 30s
+ restart: unless-stopped
+
+ valkey:
+ image: valkey/valkey:8.0.2-alpine3.21
+ command: ["valkey-server", "/usr/local/etc/valkey/valkey.conf"]
+ volumes:
+ - ./infra/valkey/valkey.conf:/usr/local/etc/valkey/valkey.conf:ro
+ secrets: [valkey_auth]
+ networks: [data]
+ healthcheck:
+ test: ["CMD-SHELL", "valkey-cli ping | grep -qE 'PONG|NOAUTH'"]
+ interval: 2s
+ timeout: 3s
+ retries: 30
+ deploy:
+ resources:
+ limits: {cpus: "0.5", memory: 128M}
+ restart: unless-stopped
+
+ migrate:
+ build:
+ context: .
+ args:
+ APP_BUILD: ${APP_BUILD:-dev}
+ image: mtusi-messenger:lab3
+ command: ["migrate"]
+ environment:
+ DATABASE_URL_FILE: /run/secrets/database_url
+ secrets: [database_url]
+ networks: [data]
+ depends_on:
+ postgres:
+ condition: service_healthy
+ deploy:
+ resources:
+ limits: {cpus: "0.5", memory: 128M}
+ restart: "no"
+
+ api:
+ image: mtusi-messenger:lab3
+ pull_policy: never
+ environment: *api-env
+ secrets: [database_url, cache_url]
+ networks: [app, data]
+ depends_on:
+ migrate:
+ condition: service_completed_successfully
+ postgres:
+ condition: service_healthy
+ valkey:
+ condition: service_healthy
+ healthcheck:
+ test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/ready"]
+ interval: 2s
+ timeout: 2s
+ start_period: 5s
+ retries: 3
+ deploy:
+ replicas: ${API_REPLICAS:-2}
+ resources:
+ limits: {cpus: "${API_CPUS:-1.0}", memory: "${API_MEMORY:-256M}"}
+ stop_grace_period: 15s
+ restart: unless-stopped
+
+ lb:
+ image: haproxy:3.0.5-alpine
+ volumes:
+ - ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
+ ports:
+ - "127.0.0.1:${APP_PORT:-8080}:8080"
+ - "[::1]:${APP_PORT:-8080}:8080"
+ networks: [app]
+ depends_on:
+ api:
+ condition: service_healthy
+ healthcheck:
+ test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8404/healthz"]
+ interval: 2s
+ timeout: 2s
+ retries: 15
+ deploy:
+ resources:
+ limits: {cpus: "${LB_CPUS:-1.0}", memory: 128M}
+ restart: unless-stopped
+
+networks:
+ app: {}
+ data: {}
+
+volumes:
+ pgdata: {}
+
+secrets:
+ pg_password:
+ file: ./secrets/pg_password
+ database_url:
+ file: ./secrets/database_url
+ cache_url:
+ file: ./secrets/cache_url
+ valkey_auth:
+ file: ./secrets/valkey_auth.conf
diff --git a/evidence/check-smoke.txt b/evidence/check-smoke.txt
new file mode 100644
index 00000000..9bb14308
--- /dev/null
+++ b/evidence/check-smoke.txt
@@ -0,0 +1,5 @@
+# 2026-10-15T18:33:57Z image label: oneshot
+$ make check
+PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
+$ make test
+PASS: lab3 public API scenario; infrastructure and grading evidence remain separate.
diff --git a/evidence/failover-kill.json b/evidence/failover-kill.json
new file mode 100644
index 00000000..51cf6918
--- /dev/null
+++ b/evidence/failover-kill.json
@@ -0,0 +1,145 @@
+{
+ "mode": "kill",
+ "workers": 8,
+ "client_timeout_s": 2.0,
+ "total": {
+ "seconds": 49.45,
+ "ok": 32527,
+ "errors": 6,
+ "ok_rps": 657.8,
+ "p50_ms": 7.5,
+ "p95_ms": 28.3,
+ "p99_ms": 32.3
+ },
+ "client_retries": 6,
+ "rounds": [
+ {
+ "replica_name": "mtusi-lab3-api-10",
+ "instance_id": "53edc66ecc4d",
+ "action": "docker kill",
+ "action_duration_s": 0.64,
+ "baseline_5s": {
+ "seconds": 5.0,
+ "ok": 3521,
+ "errors": 0,
+ "ok_rps": 704.2,
+ "p50_ms": 7.7,
+ "p95_ms": 29.1,
+ "p99_ms": 34.2
+ },
+ "after_failure": {
+ "seconds": 12.61,
+ "ok": 7342,
+ "errors": 4,
+ "ok_rps": 582.1,
+ "p50_ms": 7.5,
+ "p95_ms": 28.8,
+ "p99_ms": 32.1
+ },
+ "first_1s_after_failure": {
+ "seconds": 1.0,
+ "ok": 178,
+ "errors": 4,
+ "ok_rps": 178.0,
+ "p50_ms": 8.3,
+ "p95_ms": 36.0,
+ "p99_ms": 1009.2
+ },
+ "last_error_after_failure_s": 0.1,
+ "target_last_served_after_failure_s": 0.1,
+ "restored_healthy_after_s": 6.0,
+ "restored_back_in_rotation_after_s": 6.1,
+ "errors_sample": [
+ "e0b-8388-4f8ca05fc820/messages: expected [201], received 502"
+ ],
+ "docker_ps_before": [
+ "mtusi-lab3-api-10\trunning\tUp 45 seconds (healthy)",
+ "mtusi-lab3-api-8\trunning\tUp 22 seconds (healthy)",
+ "mtusi-lab3-lb-1\trunning\tUp About a minute (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) 8 seconds ago",
+ "mtusi-lab3-postgres-1\trunning\tUp About a minute (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp About a minute (healthy)"
+ ],
+ "docker_ps_during": [
+ "mtusi-lab3-api-10\texited\tExited (137) 12 seconds ago",
+ "mtusi-lab3-api-8\trunning\tUp 35 seconds (healthy)",
+ "mtusi-lab3-lb-1\trunning\tUp About a minute (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) 20 seconds ago",
+ "mtusi-lab3-postgres-1\trunning\tUp About a minute (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp About a minute (healthy)"
+ ]
+ },
+ {
+ "replica_name": "mtusi-lab3-api-8",
+ "instance_id": "2ba86c0a9ce9",
+ "action": "docker kill",
+ "action_duration_s": 0.71,
+ "baseline_5s": {
+ "seconds": 5.0,
+ "ok": 3648,
+ "errors": 0,
+ "ok_rps": 729.6,
+ "p50_ms": 7.2,
+ "p95_ms": 28.5,
+ "p99_ms": 32.3
+ },
+ "after_failure": {
+ "seconds": 12.63,
+ "ok": 7810,
+ "errors": 2,
+ "ok_rps": 618.4,
+ "p50_ms": 7.4,
+ "p95_ms": 28.1,
+ "p99_ms": 32.3
+ },
+ "first_1s_after_failure": {
+ "seconds": 1.0,
+ "ok": 149,
+ "errors": 2,
+ "ok_rps": 149.0,
+ "p50_ms": 15.2,
+ "p95_ms": 1005.7,
+ "p99_ms": 1009.9
+ },
+ "last_error_after_failure_s": 0.12,
+ "target_last_served_after_failure_s": 0.12,
+ "restored_healthy_after_s": 5.78,
+ "restored_back_in_rotation_after_s": 5.89,
+ "errors_sample": [
+ "e0b-8388-4f8ca05fc820/messages: expected [201], received 502"
+ ],
+ "docker_ps_before": [
+ "mtusi-lab3-api-10\trunning\tUp 9 seconds (healthy)",
+ "mtusi-lab3-api-8\trunning\tUp 45 seconds (healthy)",
+ "mtusi-lab3-lb-1\trunning\tUp About a minute (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) 30 seconds ago",
+ "mtusi-lab3-postgres-1\trunning\tUp About a minute (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp About a minute (healthy)"
+ ],
+ "docker_ps_during": [
+ "mtusi-lab3-api-10\trunning\tUp 21 seconds (healthy)",
+ "mtusi-lab3-api-8\texited\tExited (137) 12 seconds ago",
+ "mtusi-lab3-lb-1\trunning\tUp About a minute (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) 43 seconds ago",
+ "mtusi-lab3-postgres-1\trunning\tUp 2 minutes (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp 2 minutes (healthy)"
+ ]
+ }
+ ],
+ "data_check": {
+ "stored_messages": 32533,
+ "confirmed_201": 32533,
+ "lost_confirmed": 0,
+ "duplicate_ids": 0,
+ "duplicate_texts": 0,
+ "unique_confirmed": 32533
+ },
+ "docker_ps_end": [
+ "mtusi-lab3-api-10\trunning\tUp 34 seconds (healthy)",
+ "mtusi-lab3-api-8\trunning\tUp 12 seconds (healthy)",
+ "mtusi-lab3-lb-1\trunning\tUp 2 minutes (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) 55 seconds ago",
+ "mtusi-lab3-postgres-1\trunning\tUp 2 minutes (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp 2 minutes (healthy)"
+ ]
+}
diff --git a/evidence/failover-stop.json b/evidence/failover-stop.json
new file mode 100644
index 00000000..5f6e9f40
--- /dev/null
+++ b/evidence/failover-stop.json
@@ -0,0 +1,141 @@
+{
+ "mode": "stop",
+ "workers": 8,
+ "client_timeout_s": 2.0,
+ "total": {
+ "seconds": 49.43,
+ "ok": 38097,
+ "errors": 0,
+ "ok_rps": 770.8,
+ "p50_ms": 7.5,
+ "p95_ms": 26.8,
+ "p99_ms": 31.7
+ },
+ "client_retries": 0,
+ "rounds": [
+ {
+ "replica_name": "mtusi-lab3-api-10",
+ "instance_id": "53edc66ecc4d",
+ "action": "docker stop",
+ "action_duration_s": 3.67,
+ "baseline_5s": {
+ "seconds": 5.0,
+ "ok": 4010,
+ "errors": 0,
+ "ok_rps": 802.0,
+ "p50_ms": 7.1,
+ "p95_ms": 26.1,
+ "p99_ms": 31.6
+ },
+ "after_failure": {
+ "seconds": 12.61,
+ "ok": 10150,
+ "errors": 0,
+ "ok_rps": 805.1,
+ "p50_ms": 7.4,
+ "p95_ms": 26.9,
+ "p99_ms": 31.5
+ },
+ "first_1s_after_failure": {
+ "seconds": 1.0,
+ "ok": 803,
+ "errors": 0,
+ "ok_rps": 803.0,
+ "p50_ms": 7.9,
+ "p95_ms": 26.1,
+ "p99_ms": 30.9
+ },
+ "last_error_after_failure_s": null,
+ "target_last_served_after_failure_s": 1.57,
+ "restored_healthy_after_s": 5.77,
+ "restored_back_in_rotation_after_s": 5.87,
+ "errors_sample": [],
+ "docker_ps_before": [
+ "mtusi-lab3-api-10\trunning\tUp 23 seconds (healthy)",
+ "mtusi-lab3-api-8\trunning\tUp 24 seconds (healthy)",
+ "mtusi-lab3-lb-1\trunning\tUp 18 seconds (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) 16 seconds ago",
+ "mtusi-lab3-postgres-1\trunning\tUp 27 seconds (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp 27 seconds (healthy)"
+ ],
+ "docker_ps_during": [
+ "mtusi-lab3-api-10\texited\tExited (0) 9 seconds ago",
+ "mtusi-lab3-api-8\trunning\tUp 36 seconds (healthy)",
+ "mtusi-lab3-lb-1\trunning\tUp 30 seconds (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) 28 seconds ago",
+ "mtusi-lab3-postgres-1\trunning\tUp 39 seconds (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp 39 seconds (healthy)"
+ ]
+ },
+ {
+ "replica_name": "mtusi-lab3-api-8",
+ "instance_id": "2ba86c0a9ce9",
+ "action": "docker stop",
+ "action_duration_s": 3.72,
+ "baseline_5s": {
+ "seconds": 5.0,
+ "ok": 3258,
+ "errors": 0,
+ "ok_rps": 651.6,
+ "p50_ms": 7.5,
+ "p95_ms": 27.1,
+ "p99_ms": 33.2
+ },
+ "after_failure": {
+ "seconds": 12.64,
+ "ok": 9446,
+ "errors": 0,
+ "ok_rps": 747.4,
+ "p50_ms": 7.7,
+ "p95_ms": 26.9,
+ "p99_ms": 31.9
+ },
+ "first_1s_after_failure": {
+ "seconds": 1.0,
+ "ok": 752,
+ "errors": 0,
+ "ok_rps": 752.0,
+ "p50_ms": 8.1,
+ "p95_ms": 28.3,
+ "p99_ms": 31.5
+ },
+ "last_error_after_failure_s": null,
+ "target_last_served_after_failure_s": 1.42,
+ "restored_healthy_after_s": 5.99,
+ "restored_back_in_rotation_after_s": 6.1,
+ "errors_sample": [],
+ "docker_ps_before": [
+ "mtusi-lab3-api-10\trunning\tUp 9 seconds (healthy)",
+ "mtusi-lab3-api-8\trunning\tUp 46 seconds (healthy)",
+ "mtusi-lab3-lb-1\trunning\tUp 40 seconds (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) 38 seconds ago",
+ "mtusi-lab3-postgres-1\trunning\tUp 49 seconds (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp 49 seconds (healthy)"
+ ],
+ "docker_ps_during": [
+ "mtusi-lab3-api-10\trunning\tUp 21 seconds (healthy)",
+ "mtusi-lab3-api-8\texited\tExited (0) 9 seconds ago",
+ "mtusi-lab3-lb-1\trunning\tUp 52 seconds (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) 51 seconds ago",
+ "mtusi-lab3-postgres-1\trunning\tUp About a minute (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp About a minute (healthy)"
+ ]
+ }
+ ],
+ "data_check": {
+ "stored_messages": 38100,
+ "confirmed_201": 38100,
+ "lost_confirmed": 0,
+ "duplicate_ids": 0,
+ "duplicate_texts": 0,
+ "unique_confirmed": 38100
+ },
+ "docker_ps_end": [
+ "mtusi-lab3-api-10\trunning\tUp 35 seconds (healthy)",
+ "mtusi-lab3-api-8\trunning\tUp 13 seconds (healthy)",
+ "mtusi-lab3-lb-1\trunning\tUp About a minute (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) About a minute ago",
+ "mtusi-lab3-postgres-1\trunning\tUp About a minute (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp About a minute (healthy)"
+ ]
+}
diff --git a/evidence/failover.txt b/evidence/failover.txt
new file mode 100644
index 00000000..42e2a3b7
--- /dev/null
+++ b/evidence/failover.txt
@@ -0,0 +1,82 @@
+===== run 1 18:34:29
+## api before:
+2ba86c0a9ce9 mtusi-lab3-api-8 Up 17 seconds (healthy)
+53edc66ecc4d mtusi-lab3-api-10 Up 17 seconds (healthy)
+$ make test-failover ACTION_SCRIPT=scripts/stop-one.cmd
+Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
+{"observed_instances_before": 2, "successful_writes": 136, "failed_attempts": 0, "first_recovery_seconds": 3.888}
+PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+## api after (stopped replica must be Exited):
+2ba86c0a9ce9 mtusi-lab3-api-8 Exited (0) 11 seconds ago
+53edc66ecc4d mtusi-lab3-api-10 Up 33 seconds (healthy)
+===== run 2 18:34:54
+## api before:
+2ba86c0a9ce9 mtusi-lab3-api-8 Up 6 seconds (healthy)
+53edc66ecc4d mtusi-lab3-api-10 Up 42 seconds (healthy)
+$ make test-failover ACTION_SCRIPT=scripts/stop-one.cmd
+Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
+{"observed_instances_before": 2, "successful_writes": 137, "failed_attempts": 0, "first_recovery_seconds": 3.869}
+PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+## api after (stopped replica must be Exited):
+2ba86c0a9ce9 mtusi-lab3-api-8 Exited (0) 11 seconds ago
+53edc66ecc4d mtusi-lab3-api-10 Up 58 seconds (healthy)
+===== run 3 18:35:19
+## api before:
+2ba86c0a9ce9 mtusi-lab3-api-8 Up 6 seconds (healthy)
+53edc66ecc4d mtusi-lab3-api-10 Up About a minute (healthy)
+$ make test-failover ACTION_SCRIPT=scripts/stop-one.cmd
+Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
+{"observed_instances_before": 2, "successful_writes": 136, "failed_attempts": 0, "first_recovery_seconds": 3.763}
+PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+## api after (stopped replica must be Exited):
+2ba86c0a9ce9 mtusi-lab3-api-8 Exited (0) 11 seconds ago
+53edc66ecc4d mtusi-lab3-api-10 Up About a minute (healthy)
+===== run 4 18:35:44
+## api before:
+2ba86c0a9ce9 mtusi-lab3-api-8 Up 6 seconds (healthy)
+53edc66ecc4d mtusi-lab3-api-10 Up About a minute (healthy)
+$ make test-failover ACTION_SCRIPT=scripts/stop-one.cmd
+Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
+{"observed_instances_before": 2, "successful_writes": 138, "failed_attempts": 0, "first_recovery_seconds": 3.842}
+PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+## api after (stopped replica must be Exited):
+2ba86c0a9ce9 mtusi-lab3-api-8 Exited (0) 11 seconds ago
+53edc66ecc4d mtusi-lab3-api-10 Up About a minute (healthy)
+===== run 5 18:36:09
+## api before:
+2ba86c0a9ce9 mtusi-lab3-api-8 Up 6 seconds (healthy)
+53edc66ecc4d mtusi-lab3-api-10 Up About a minute (healthy)
+$ make test-failover ACTION_SCRIPT=scripts/stop-one.cmd
+Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
+{"observed_instances_before": 2, "successful_writes": 139, "failed_attempts": 0, "first_recovery_seconds": 3.913}
+PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+## api after (stopped replica must be Exited):
+2ba86c0a9ce9 mtusi-lab3-api-8 Exited (0) 11 seconds ago
+53edc66ecc4d mtusi-lab3-api-10 Up 2 minutes (healthy)
+===== run 6 18:36:34
+## api before:
+2ba86c0a9ce9 mtusi-lab3-api-8 Up 6 seconds (healthy)
+53edc66ecc4d mtusi-lab3-api-10 Up 2 minutes (healthy)
+$ make test-failover ACTION_SCRIPT=scripts/stop-one.cmd
+Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
+{"observed_instances_before": 2, "successful_writes": 137, "failed_attempts": 0, "first_recovery_seconds": 3.806}
+PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+## api after (stopped replica must be Exited):
+2ba86c0a9ce9 mtusi-lab3-api-8 Exited (0) 11 seconds ago
+53edc66ecc4d mtusi-lab3-api-10 Up 2 minutes (healthy)
+mtusi-lab3-api-10 Up 2 minutes (healthy)
+mtusi-lab3-api-8 Up 6 seconds (healthy)
+mtusi-lab3-lb-1 Up 2 minutes (healthy)
+mtusi-lab3-postgres-1 Up 2 minutes (healthy)
+mtusi-lab3-valkey-1 Up 2 minutes (healthy)
+===== shifted run 1 (+1 LB request) 18:37:12
+## api before:
+2ba86c0a9ce9 mtusi-lab3-api-8 Up 19 seconds (healthy)
+53edc66ecc4d mtusi-lab3-api-10 Up 2 minutes (healthy)
+$ make test-failover ACTION_SCRIPT=scripts/stop-one.cmd
+Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
+{"observed_instances_before": 2, "successful_writes": 139, "failed_attempts": 0, "first_recovery_seconds": 3.905}
+PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+## api after (stopped replica must be Exited):
+2ba86c0a9ce9 mtusi-lab3-api-8 Up 35 seconds (healthy)
+53edc66ecc4d mtusi-lab3-api-10 Exited (0) 11 seconds ago
diff --git a/evidence/hooks-sh.txt b/evidence/hooks-sh.txt
new file mode 100644
index 00000000..752e074a
--- /dev/null
+++ b/evidence/hooks-sh.txt
@@ -0,0 +1,9 @@
+$ TARGET_INSTANCE_ID=2ba86c0a9ce9 sh scripts/stop-one.sh
+stopped api container 2ba86c0a9ce9
+rc=0
+unexpected instance id format
+rc(bad id)=2
+2ba86c0a9ce9 mtusi-lab3-api-8 Exited (0) Less than a second ago
+53edc66ecc4d mtusi-lab3-api-10 Up 18 seconds (healthy)
+$ sh scripts/restart.sh
+rc=0
diff --git a/evidence/infra.txt b/evidence/infra.txt
new file mode 100644
index 00000000..5bdd0b7c
--- /dev/null
+++ b/evidence/infra.txt
@@ -0,0 +1,13 @@
+$ docker compose ps
+mtusi-lab3-api-11 mtusi-messenger:lab3 Up 30 seconds (healthy) 8080/tcp
+mtusi-lab3-api-12 mtusi-messenger:lab3 Up 20 seconds (healthy) 8080/tcp
+mtusi-lab3-lb-1 haproxy:3.0.5-alpine Up 2 minutes (healthy) 127.0.0.1:8080->8080/tcp, [::1]:8080->8080/tcp
+mtusi-lab3-postgres-1 postgres:17.2-alpine3.21 Up 3 minutes (healthy) 5432/tcp
+mtusi-lab3-valkey-1 valkey/valkey:8.0.2-alpine3.21 Up 3 minutes (healthy) 6379/tcp
+
+$ docker inspect (limits, published ports)
+/mtusi-lab3-api-11 cpus=1000000000 mem=268435456 ports={}
+/mtusi-lab3-api-12 cpus=1000000000 mem=268435456 ports={}
+/mtusi-lab3-lb-1 cpus=1000000000 mem=134217728 ports={"8080/tcp":[{"HostIp":"127.0.0.1","HostPort":"8080"},{"HostIp":"::1","HostPort":"8080"}]}
+/mtusi-lab3-postgres-1 cpus=2000000000 mem=1073741824 ports={}
+/mtusi-lab3-valkey-1 cpus=500000000 mem=134217728 ports={}
diff --git a/evidence/persistence.txt b/evidence/persistence.txt
new file mode 100644
index 00000000..9bf95444
--- /dev/null
+++ b/evidence/persistence.txt
@@ -0,0 +1,20 @@
+## before
+mtusi-lab3-api-10 Up 22 seconds (healthy)
+mtusi-lab3-api-8 Up 22 seconds (healthy)
+mtusi-lab3-lb-1 Up 44 minutes (healthy)
+mtusi-lab3-postgres-1 Up 48 minutes (healthy)
+mtusi-lab3-valkey-1 Up 48 minutes (healthy)
+/mtusi-lab3-api-10 started=2026-10-15T18:33:39.363537423Z
+/mtusi-lab3-api-8 started=2026-10-15T18:33:39.115171904Z
+/mtusi-lab3-lb-1 started=2026-10-15T17:49:37.609675273Z
+/mtusi-lab3-postgres-1 started=2026-10-15T17:45:25.041848495Z
+/mtusi-lab3-valkey-1 started=2026-10-15T17:45:25.037622696Z
+$ make test-persistence ACTION_SCRIPT=scripts/restart.cmd
+Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
+PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
+## after
+/mtusi-lab3-api-10 started=2026-10-15T18:34:12.666295127Z
+/mtusi-lab3-api-8 started=2026-10-15T18:34:12.431124585Z
+/mtusi-lab3-lb-1 started=2026-10-15T18:34:18.429727978Z
+/mtusi-lab3-postgres-1 started=2026-10-15T18:34:09.034550134Z
+/mtusi-lab3-valkey-1 started=2026-10-15T18:34:08.538273227Z
diff --git a/evidence/rolling-update.json b/evidence/rolling-update.json
new file mode 100644
index 00000000..39c82f7e
--- /dev/null
+++ b/evidence/rolling-update.json
@@ -0,0 +1,61 @@
+{
+ "build_label": "final-rollout",
+ "replicas": 2,
+ "workers": 8,
+ "before_rollout_5s": {
+ "seconds": 5.0,
+ "ok": 3946,
+ "errors": 0,
+ "ok_rps": 789.2,
+ "p50_ms": 6.8,
+ "p95_ms": 28.0,
+ "p99_ms": 31.8
+ },
+ "during_rollout": {
+ "seconds": 27.61,
+ "ok": 22423,
+ "errors": 0,
+ "ok_rps": 812.1,
+ "p50_ms": 7.2,
+ "p95_ms": 26.7,
+ "p99_ms": 31.2
+ },
+ "after_rollout_5s": {
+ "seconds": 5.0,
+ "ok": 4023,
+ "errors": 0,
+ "ok_rps": 804.6,
+ "p50_ms": 6.7,
+ "p95_ms": 29.1,
+ "p99_ms": 31.8
+ },
+ "client_retries": 0,
+ "error_samples": [],
+ "all_new_label": true,
+ "data_check": {
+ "stored_messages": 30400,
+ "confirmed_201": 30400,
+ "lost_confirmed": 0,
+ "duplicate_ids": 0,
+ "duplicate_texts": 0,
+ "unique_confirmed": 30400
+ },
+ "log": [
+ "old replicas: [('mtusi-lab3-api-10', '53edc66ecc4d', 'oneshot'), ('mtusi-lab3-api-8', '2ba86c0a9ce9', 'oneshot')]",
+ "built image with label final-rollout in 4.7s",
+ "migrations applied once (advisory lock, idempotent)",
+ "new mtusi-lab3-api-11 (2103f38db2bd) healthy and serving; label=final-rollout",
+ "old mtusi-lab3-api-10 (53edc66ecc4d) drained+removed in 4.0s",
+ "new mtusi-lab3-api-12 (5f090e0a56f6) healthy and serving; label=final-rollout",
+ "old mtusi-lab3-api-8 (2ba86c0a9ce9) drained+removed in 4.0s",
+ "new replicas: [('mtusi-lab3-api-11', '2103f38db2bd', 'final-rollout'), ('mtusi-lab3-api-12', '5f090e0a56f6', 'final-rollout')]"
+ ],
+ "docker_ps_end": [
+ "mtusi-lab3-api-11\trunning\tUp 30 seconds (healthy)",
+ "mtusi-lab3-api-12\trunning\tUp 19 seconds (healthy)",
+ "mtusi-lab3-lb-1\trunning\tUp 2 minutes (healthy)",
+ "mtusi-lab3-migrate-1\texited\tExited (0) 45 seconds ago",
+ "mtusi-lab3-postgres-1\trunning\tUp 2 minutes (healthy)",
+ "mtusi-lab3-valkey-1\trunning\tUp 2 minutes (healthy)"
+ ]
+}
diff --git a/evidence/student-tests.json b/evidence/student-tests.json
new file mode 100644
index 00000000..5bf3c4e9
--- /dev/null
+++ b/evidence/student-tests.json
@@ -0,0 +1,42 @@
+[
+ {
+ "test": "one session served by >=2 replicas without re-login (no stickiness)",
+ "result": "PASS",
+ "detail": "distribution [15, 15]"
+ },
+ {
+ "test": "X-Instance-Id is present on errors and health too",
+ "result": "PASS",
+ "detail": null
+ },
+ {
+ "test": "Idempotency-Key missing or malformed -> 400, nothing stored",
+ "result": "PASS",
+ "detail": null
+ },
+ {
+ "test": "concurrent replay of one key through different replicas -> exactly one message",
+ "result": "PASS",
+ "detail": "24 parallel requests via 2 replicas -> 1 message"
+ },
+ {
+ "test": "replay is semantic: JSON key order/whitespace does not matter; other body -> 409",
+ "result": "PASS",
+ "detail": null
+ },
+ {
+ "test": "key scope = user + chat: same key is independent for other user / other chat",
+ "result": "PASS",
+ "detail": null
+ },
+ {
+ "test": "logout is visible on every replica immediately (shared sessions)",
+ "result": "PASS",
+ "detail": "revoked token rejected by 2 replicas"
+ },
+ {
+ "test": "replay re-checks the session and chat access",
+ "result": "PASS",
+ "detail": null
+ }
+]
diff --git a/evidence/student-tests.txt b/evidence/student-tests.txt
new file mode 100644
index 00000000..c3c5eec4
--- /dev/null
+++ b/evidence/student-tests.txt
@@ -0,0 +1,9 @@
+PASS one session served by >=2 replicas without re-login (no stickiness) - distribution [15, 15]
+PASS X-Instance-Id is present on errors and health too -
+PASS Idempotency-Key missing or malformed -> 400, nothing stored -
+PASS concurrent replay of one key through different replicas -> exactly one message - 24 parallel requests via 2 replicas -> 1 message
+PASS replay is semantic: JSON key order/whitespace does not matter; other body -> 409 -
+PASS key scope = user + chat: same key is independent for other user / other chat -
+PASS logout is visible on every replica immediately (shared sessions) - revoked token rejected by 2 replicas
+PASS replay re-checks the session and chat access -
+8/8 passed
diff --git a/evidence/track1/fixed-latency.svg b/evidence/track1/fixed-latency.svg
new file mode 100644
index 00000000..7ef3ad52
--- /dev/null
+++ b/evidence/track1/fixed-latency.svg
@@ -0,0 +1 @@
+
diff --git a/evidence/track1/fixed-rps.svg b/evidence/track1/fixed-rps.svg
new file mode 100644
index 00000000..fa488158
--- /dev/null
+++ b/evidence/track1/fixed-rps.svg
@@ -0,0 +1 @@
+
diff --git a/evidence/track1/growth-latency.svg b/evidence/track1/growth-latency.svg
new file mode 100644
index 00000000..ddeb2ea8
--- /dev/null
+++ b/evidence/track1/growth-latency.svg
@@ -0,0 +1 @@
+
diff --git a/evidence/track1/growth.svg b/evidence/track1/growth.svg
new file mode 100644
index 00000000..b3644e95
--- /dev/null
+++ b/evidence/track1/growth.svg
@@ -0,0 +1 @@
+
diff --git a/evidence/track1/improvement-p95.svg b/evidence/track1/improvement-p95.svg
new file mode 100644
index 00000000..b2176b1b
--- /dev/null
+++ b/evidence/track1/improvement-p95.svg
@@ -0,0 +1 @@
+
diff --git a/evidence/track1/improvement-rps.svg b/evidence/track1/improvement-rps.svg
new file mode 100644
index 00000000..15e3e531
--- /dev/null
+++ b/evidence/track1/improvement-rps.svg
@@ -0,0 +1 @@
+
diff --git a/evidence/track1/raw/f1x2.0-r1.json b/evidence/track1/raw/f1x2.0-r1.json
new file mode 100644
index 00000000..8b066119
--- /dev/null
+++ b/evidence/track1/raw/f1x2.0-r1.json
@@ -0,0 +1,61 @@
+{
+ "label": "f1x2.0-r1",
+ "config": "f1x2.0",
+ "series": "fixed",
+ "repeat": 1,
+ "replicas": 1,
+ "cpus_per_replica": "2.0",
+ "mem_per_replica": "512M",
+ "db_pool_per_replica": 20,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087091,
+ "instances": [
+ "eb7bddca1968"
+ ],
+ "rps": 3271.5,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 25.68,
+ "p(95)": 71.76,
+ "p(99)": 77.86,
+ "max": 271.23
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 169.6,
+ "cpu_pct_max_one_container": 205.1,
+ "mem_mib_mean": 37.8,
+ "containers": 1
+ },
+ "lb": {
+ "cpu_pct_mean": 38.3,
+ "cpu_pct_max_one_container": 44.9,
+ "mem_mib_mean": 33.1,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 180.0,
+ "cpu_pct_max_one_container": 208.7,
+ "mem_mib_mean": 235.9,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 7.9,
+ "cpu_pct_max_one_container": 9.8,
+ "mem_mib_mean": 6.6,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 14.6,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 12.06,
+ "CPU:-": 1.31,
+ "IO:WalSync": 0.88,
+ "Client:ClientRead": 0.38
+ }
+ }
+}
diff --git a/evidence/track1/raw/f1x2.0-r1.k6.json b/evidence/track1/raw/f1x2.0-r1.k6.json
new file mode 100644
index 00000000..eaa0ade4
--- /dev/null
+++ b/evidence/track1/raw/f1x2.0-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "http_reqs": {
+ "count": 102494,
+ "rate": 3271.4704011992644
+ },
+ "http_req_sending": {
+ "p(95)": 0.012611,
+ "p(99)": 0.03636834999999996,
+ "max": 29.656333,
+ "avg": 0.013127502995297507,
+ "p(50)": 0.006902
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 102494,
+ "value": 0
+ },
+ "http_req_blocked": {
+ "p(50)": 0.0017575,
+ "p(95)": 0.002771,
+ "p(99)": 0.00402,
+ "max": 33.108852,
+ "avg": 0.010311826750834384
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "data_received": {
+ "count": 165727871,
+ "rate": 5289810.375536811
+ },
+ "http_req_duration": {
+ "p(99)": 77.85758251999997,
+ "max": 271.228701,
+ "avg": 37.377396409165435,
+ "p(50)": 25.6792455,
+ "p(95)": 71.75683549999997
+ },
+ "iterations": {
+ "count": 102398,
+ "rate": 3268.406210529419
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_connecting": {
+ "p(99)": 0,
+ "max": 32.594696,
+ "avg": 0.005922264122777921,
+ "p(50)": 0,
+ "p(95)": 0
+ },
+ "http_req_duration{expected_response:true}": {
+ "max": 271.228701,
+ "avg": 37.377396409165435,
+ "p(50)": 25.6792455,
+ "p(95)": 71.75683549999997,
+ "p(99)": 77.85758251999997
+ },
+ "iteration_duration": {
+ "p(99)": 77.93512477,
+ "max": 271.279332,
+ "avg": 37.487560087482244,
+ "p(50)": 25.76751,
+ "p(95)": 71.8403659
+ },
+ "http_req_receiving": {
+ "p(50)": 0.026305,
+ "p(95)": 0.07539669999999998,
+ "p(99)": 0.1622339199999996,
+ "max": 26.327731,
+ "avg": 0.03552721832497523
+ },
+ "http_req_waiting": {
+ "avg": 37.32874168784534,
+ "p(50)": 25.636770499999997,
+ "p(95)": 71.72085014999999,
+ "p(99)": 77.82799272999999,
+ "max": 271.210072
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "data_sent": {
+ "rate": 920639.4701322336,
+ "count": 28843306
+ },
+ "checks": {
+ "passes": 102398,
+ "fails": 0,
+ "value": 1
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 30507,
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200"
+ },
+ "post 201": {
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 71891,
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201"
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/f1x2.0-r2.json b/evidence/track1/raw/f1x2.0-r2.json
new file mode 100644
index 00000000..104297e1
--- /dev/null
+++ b/evidence/track1/raw/f1x2.0-r2.json
@@ -0,0 +1,61 @@
+{
+ "label": "f1x2.0-r2",
+ "config": "f1x2.0",
+ "series": "fixed",
+ "repeat": 2,
+ "replicas": 1,
+ "cpus_per_replica": "2.0",
+ "mem_per_replica": "512M",
+ "db_pool_per_replica": 20,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087266,
+ "instances": [
+ "236ee5fe31b0"
+ ],
+ "rps": 3835.0,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 27.22,
+ "p(95)": 58.1,
+ "p(99)": 66.73,
+ "max": 81.53
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 182.9,
+ "cpu_pct_max_one_container": 207.7,
+ "mem_mib_mean": 35.5,
+ "containers": 1
+ },
+ "lb": {
+ "cpu_pct_mean": 40.8,
+ "cpu_pct_max_one_container": 48.2,
+ "mem_mib_mean": 33.4,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 166.7,
+ "cpu_pct_max_one_container": 197.0,
+ "mem_mib_mean": 283.9,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 7.3,
+ "cpu_pct_max_one_container": 8.8,
+ "mem_mib_mean": 6.7,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 11.8,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 10.12,
+ "IO:WalSync": 0.81,
+ "CPU:-": 0.56,
+ "Client:ClientRead": 0.25
+ }
+ }
+}
diff --git a/evidence/track1/raw/f1x2.0-r2.k6.json b/evidence/track1/raw/f1x2.0-r2.k6.json
new file mode 100644
index 00000000..f536c794
--- /dev/null
+++ b/evidence/track1/raw/f1x2.0-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "checks": {
+ "passes": 119924,
+ "fails": 0,
+ "value": 1
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "data_received": {
+ "count": 195936586,
+ "rate": 6260713.524149038
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 31.924565649507795,
+ "p(50)": 27.221169,
+ "p(95)": 58.1021782,
+ "p(99)": 66.72710961999995,
+ "max": 81.529032
+ },
+ "http_req_blocked": {
+ "p(95)": 0.00256,
+ "p(99)": 0.0037778099999999978,
+ "max": 38.624946,
+ "avg": 0.008886539293451247,
+ "p(50)": 0.001505
+ },
+ "iteration_duration": {
+ "avg": 32.023175228978225,
+ "p(50)": 27.306818,
+ "p(95)": 58.18693169999997,
+ "p(99)": 66.81468741000006,
+ "max": 95.064469
+ },
+ "http_req_sending": {
+ "max": 6.777963,
+ "avg": 0.00913949931678048,
+ "p(50)": 0.006263,
+ "p(95)": 0.010762,
+ "p(99)": 0.033918199999999954
+ },
+ "http_req_tls_handshaking": {
+ "p(99)": 0,
+ "max": 0,
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 120020,
+ "value": 0
+ },
+ "data_sent": {
+ "count": 33734360,
+ "rate": 1077905.7050657826
+ },
+ "http_req_connecting": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 36.734576,
+ "avg": 0.005984908023662723,
+ "p(50)": 0
+ },
+ "iterations": {
+ "count": 119924,
+ "rate": 3831.9020658553745
+ },
+ "http_reqs": {
+ "count": 120020,
+ "rate": 3834.9695302355
+ },
+ "http_req_duration": {
+ "p(50)": 27.221169,
+ "p(95)": 58.1021782,
+ "p(99)": 66.72710961999995,
+ "max": 81.529032,
+ "avg": 31.924565649507795
+ },
+ "http_req_waiting": {
+ "p(95)": 58.05678164999999,
+ "p(99)": 66.67941776,
+ "max": 81.505296,
+ "avg": 31.87998371997161,
+ "p(50)": 27.1824725
+ },
+ "http_req_receiving": {
+ "avg": 0.035442430219963815,
+ "p(50)": 0.023857,
+ "p(95)": 0.07770214999999973,
+ "p(99)": 0.24852368999999988,
+ "max": 19.49618
+ }
+ },
+ "root_group": {
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "post 201": {
+ "passes": 83776,
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9"
+ },
+ "get 200": {
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 36148,
+ "fails": 0,
+ "name": "get 200"
+ }
+ },
+ "name": ""
+ }
+}
diff --git a/evidence/track1/raw/f1x2.0-r3.json b/evidence/track1/raw/f1x2.0-r3.json
new file mode 100644
index 00000000..92e25a22
--- /dev/null
+++ b/evidence/track1/raw/f1x2.0-r3.json
@@ -0,0 +1,61 @@
+{
+ "label": "f1x2.0-r3",
+ "config": "f1x2.0",
+ "series": "fixed",
+ "repeat": 3,
+ "replicas": 1,
+ "cpus_per_replica": "2.0",
+ "mem_per_replica": "512M",
+ "db_pool_per_replica": 20,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087438,
+ "instances": [
+ "72332eeca725"
+ ],
+ "rps": 3800.2,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 26.85,
+ "p(95)": 61.21,
+ "p(99)": 70.07,
+ "max": 92.37
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 183.3,
+ "cpu_pct_max_one_container": 209.1,
+ "mem_mib_mean": 36.9,
+ "containers": 1
+ },
+ "lb": {
+ "cpu_pct_mean": 40.7,
+ "cpu_pct_max_one_container": 49.2,
+ "mem_mib_mean": 33.7,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 167.0,
+ "cpu_pct_max_one_container": 194.7,
+ "mem_mib_mean": 377.7,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 7.1,
+ "cpu_pct_max_one_container": 8.4,
+ "mem_mib_mean": 6.8,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 12.6,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 10.62,
+ "Client:ClientRead": 1.0,
+ "IO:WalSync": 0.75,
+ "CPU:-": 0.25
+ }
+ }
+}
diff --git a/evidence/track1/raw/f1x2.0-r3.k6.json b/evidence/track1/raw/f1x2.0-r3.k6.json
new file mode 100644
index 00000000..53219c4c
--- /dev/null
+++ b/evidence/track1/raw/f1x2.0-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "iterations": {
+ "count": 118755,
+ "rate": 3797.1111048388216
+ },
+ "http_req_sending": {
+ "p(95)": 0.0106265,
+ "p(99)": 0.0339445,
+ "max": 24.216405,
+ "avg": 0.008522487610537607,
+ "p(50)": 0.006194
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "data_sent": {
+ "count": 33442643,
+ "rate": 1069305.9754154375
+ },
+ "http_req_duration": {
+ "max": 92.373842,
+ "avg": 32.225616086502775,
+ "p(50)": 26.849547,
+ "p(95)": 61.205169999999995,
+ "p(99)": 70.067594
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "http_reqs": {
+ "rate": 3800.1806401515623,
+ "count": 118851
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_waiting": {
+ "max": 92.35524,
+ "avg": 32.17574660962037,
+ "p(50)": 26.802449,
+ "p(95)": 61.15661,
+ "p(99)": 70.0384545
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(99)": 70.067594,
+ "max": 92.373842,
+ "avg": 32.225616086502775,
+ "p(50)": 26.849547,
+ "p(95)": 61.205169999999995
+ },
+ "data_received": {
+ "count": 192545382,
+ "rate": 6156508.847439121
+ },
+ "iteration_duration": {
+ "avg": 32.324557326663765,
+ "p(50)": 26.933833,
+ "p(95)": 61.28760969999999,
+ "p(99)": 70.14642709999998,
+ "max": 92.437093
+ },
+ "http_req_blocked": {
+ "p(99)": 0.0037735,
+ "max": 34.345141,
+ "avg": 0.010936642476714789,
+ "p(50)": 0.001499,
+ "p(95)": 0.002561
+ },
+ "http_req_receiving": {
+ "avg": 0.04134698927228189,
+ "p(50)": 0.023631,
+ "p(95)": 0.079075,
+ "p(99)": 0.274999,
+ "max": 46.844089
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 118851,
+ "value": 0
+ },
+ "http_req_connecting": {
+ "avg": 0.008416915490824644,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 30.56625
+ },
+ "checks": {
+ "passes": 118755,
+ "fails": 0,
+ "value": 1
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "passes": 35446,
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c"
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 83309,
+ "fails": 0
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/f2x1.0-r1.json b/evidence/track1/raw/f2x1.0-r1.json
new file mode 100644
index 00000000..88a53a04
--- /dev/null
+++ b/evidence/track1/raw/f2x1.0-r1.json
@@ -0,0 +1,63 @@
+{
+ "label": "f2x1.0-r1",
+ "config": "f2x1.0",
+ "series": "fixed",
+ "repeat": 1,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087149,
+ "instances": [
+ "59acc88b4c36",
+ "8be43bf4b8e5"
+ ],
+ "rps": 3520.0,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 30.55,
+ "p(95)": 75.42,
+ "p(99)": 88.12,
+ "max": 140.98
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 192.2,
+ "cpu_pct_max_one_container": 105.2,
+ "mem_mib_mean": 52.7,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 43.6,
+ "cpu_pct_max_one_container": 47.6,
+ "mem_mib_mean": 33.6,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 151.8,
+ "cpu_pct_max_one_container": 167.6,
+ "mem_mib_mean": 241.7,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.7,
+ "cpu_pct_max_one_container": 10.3,
+ "mem_mib_mean": 7.0,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 9.6,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 7.88,
+ "IO:WalSync": 0.62,
+ "CPU:-": 0.56,
+ "Client:ClientRead": 0.5,
+ "IO:WalInitSync": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/f2x1.0-r1.k6.json b/evidence/track1/raw/f2x1.0-r1.k6.json
new file mode 100644
index 00000000..be57a7db
--- /dev/null
+++ b/evidence/track1/raw/f2x1.0-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 33103,
+ "fails": 0
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 77284,
+ "fails": 0
+ }
+ },
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {}
+ },
+ "metrics": {
+ "http_req_sending": {
+ "p(99)": 0.036220639999999665,
+ "max": 24.067839,
+ "avg": 0.009216171555804986,
+ "p(50)": 0.006475,
+ "p(95)": 0.011691
+ },
+ "vus": {
+ "max": 128,
+ "value": 128,
+ "min": 0
+ },
+ "iterations": {
+ "count": 110387,
+ "rate": 3516.9908106481457
+ },
+ "http_req_waiting": {
+ "p(95)": 75.3789597,
+ "p(99)": 88.0739802,
+ "max": 140.951951,
+ "avg": 34.65638822611634,
+ "p(50)": 30.510377
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 110483,
+ "value": 0
+ },
+ "http_req_receiving": {
+ "max": 48.158856,
+ "avg": 0.036650952354661204,
+ "p(50)": 0.025715,
+ "p(95)": 0.08060009999999988,
+ "p(99)": 0.19054015999999993
+ },
+ "http_reqs": {
+ "count": 110483,
+ "rate": 3520.049423689738
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 34.70225535002638,
+ "p(50)": 30.553636,
+ "p(95)": 75.42159079999998,
+ "p(99)": 88.11721265999999,
+ "max": 140.980162
+ },
+ "http_req_connecting": {
+ "avg": 0.003714572739697509,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 23.562433
+ },
+ "iteration_duration": {
+ "avg": 34.80222628253347,
+ "p(50)": 30.665349,
+ "p(95)": 75.5157945,
+ "p(99)": 88.20836354,
+ "max": 141.042844
+ },
+ "data_sent": {
+ "count": 31070443,
+ "rate": 989921.4809150263
+ },
+ "http_req_duration": {
+ "p(99)": 88.11721265999999,
+ "max": 140.980162,
+ "avg": 34.70225535002638,
+ "p(50)": 30.553636,
+ "p(95)": 75.42159079999998
+ },
+ "vus_max": {
+ "min": 128,
+ "max": 128,
+ "value": 128
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "checks": {
+ "passes": 110387,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_blocked": {
+ "p(50)": 0.001593,
+ "p(95)": 0.002615,
+ "p(99)": 0.0037571799999999928,
+ "max": 23.856205,
+ "avg": 0.006409631698994381
+ },
+ "data_received": {
+ "count": 179525398,
+ "rate": 5719778.371039624
+ }
+ }
+}
diff --git a/evidence/track1/raw/f2x1.0-r2.json b/evidence/track1/raw/f2x1.0-r2.json
new file mode 100644
index 00000000..7aa26cf9
--- /dev/null
+++ b/evidence/track1/raw/f2x1.0-r2.json
@@ -0,0 +1,63 @@
+{
+ "label": "f2x1.0-r2",
+ "config": "f2x1.0",
+ "series": "fixed",
+ "repeat": 2,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087324,
+ "instances": [
+ "11236552e9d7",
+ "3efc1fd5870c"
+ ],
+ "rps": 3518.7,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 30.41,
+ "p(95)": 82.7,
+ "p(99)": 92.54,
+ "max": 122.99
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 185.9,
+ "cpu_pct_max_one_container": 105.8,
+ "mem_mib_mean": 52.4,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 43.9,
+ "cpu_pct_max_one_container": 50.5,
+ "mem_mib_mean": 33.7,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 163.6,
+ "cpu_pct_max_one_container": 186.9,
+ "mem_mib_mean": 313.9,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.5,
+ "cpu_pct_max_one_container": 10.7,
+ "mem_mib_mean": 6.9,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 11.1,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 9.19,
+ "CPU:-": 0.81,
+ "IO:WalSync": 0.69,
+ "Client:ClientRead": 0.38,
+ "IO:WalWrite": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/f2x1.0-r2.k6.json b/evidence/track1/raw/f2x1.0-r2.k6.json
new file mode 100644
index 00000000..e9a08cdc
--- /dev/null
+++ b/evidence/track1/raw/f2x1.0-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 77263,
+ "fails": 0
+ },
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 32886,
+ "fails": 0
+ }
+ },
+ "name": "",
+ "path": ""
+ },
+ "metrics": {
+ "http_req_waiting": {
+ "p(95)": 82.6679004,
+ "p(99)": 92.5112522,
+ "max": 122.965025,
+ "avg": 34.70016155569887,
+ "p(50)": 30.34024
+ },
+ "http_req_blocked": {
+ "avg": 0.013214196317293928,
+ "p(50)": 0.001491,
+ "p(95)": 0.002535,
+ "p(99)": 0.003723,
+ "max": 34.926459
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 110245,
+ "value": 0
+ },
+ "http_req_sending": {
+ "max": 5.156442,
+ "avg": 0.009305996897818442,
+ "p(50)": 0.006198,
+ "p(95)": 0.01066,
+ "p(99)": 0.034641559999999995
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 34.74429430536542,
+ "p(50)": 30.405632,
+ "p(95)": 82.70486079999999,
+ "p(99)": 92.54381079999999,
+ "max": 122.98958
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_connecting": {
+ "avg": 0.010659302526191664,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 34.894892
+ },
+ "http_reqs": {
+ "count": 110245,
+ "rate": 3518.7175109149284
+ },
+ "http_req_duration": {
+ "p(99)": 92.54381079999999,
+ "max": 122.98958,
+ "avg": 34.74429430536542,
+ "p(50)": 30.405632,
+ "p(95)": 82.70486079999999
+ },
+ "checks": {
+ "fails": 0,
+ "passes": 110149,
+ "value": 1
+ },
+ "data_received": {
+ "count": 178633163,
+ "rate": 5701479.783012569
+ },
+ "iteration_duration": {
+ "max": 123.056583,
+ "avg": 34.848619690791104,
+ "p(50)": 30.562831,
+ "p(95)": 82.79570459999998,
+ "p(99)": 92.62756048000003
+ },
+ "iterations": {
+ "rate": 3515.6534546670455,
+ "count": 110149
+ },
+ "vus": {
+ "max": 128,
+ "value": 128,
+ "min": 0
+ },
+ "data_sent": {
+ "rate": 990040.5237477202,
+ "count": 31018977
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "http_req_receiving": {
+ "avg": 0.03482675276883321,
+ "p(50)": 0.02409,
+ "p(95)": 0.07841019999999994,
+ "p(99)": 0.21037239999999985,
+ "max": 36.301309
+ }
+ }
+}
diff --git a/evidence/track1/raw/f2x1.0-r3.json b/evidence/track1/raw/f2x1.0-r3.json
new file mode 100644
index 00000000..0387085c
--- /dev/null
+++ b/evidence/track1/raw/f2x1.0-r3.json
@@ -0,0 +1,62 @@
+{
+ "label": "f2x1.0-r3",
+ "config": "f2x1.0",
+ "series": "fixed",
+ "repeat": 3,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087496,
+ "instances": [
+ "1665a4387fba",
+ "9304633f808b"
+ ],
+ "rps": 3571.6,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 29.7,
+ "p(95)": 80.01,
+ "p(99)": 93.27,
+ "max": 120.52
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 166.3,
+ "cpu_pct_max_one_container": 105.7,
+ "mem_mib_mean": 57.1,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 39.4,
+ "cpu_pct_max_one_container": 48.4,
+ "mem_mib_mean": 34.1,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 145.7,
+ "cpu_pct_max_one_container": 183.6,
+ "mem_mib_mean": 397.9,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 6.9,
+ "cpu_pct_max_one_container": 8.8,
+ "mem_mib_mean": 6.9,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 18,
+ "active_backends_mean": 11.5,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 9.33,
+ "CPU:-": 1.22,
+ "IO:WalSync": 0.67,
+ "Client:ClientRead": 0.28
+ }
+ }
+}
diff --git a/evidence/track1/raw/f2x1.0-r3.k6.json b/evidence/track1/raw/f2x1.0-r3.k6.json
new file mode 100644
index 00000000..3521ca33
--- /dev/null
+++ b/evidence/track1/raw/f2x1.0-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 33722,
+ "fails": 0
+ },
+ "post 201": {
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 78064,
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201"
+ }
+ }
+ },
+ "metrics": {
+ "http_req_duration{expected_response:true}": {
+ "p(50)": 29.695762000000002,
+ "p(95)": 80.00539605,
+ "p(99)": 93.26696904,
+ "max": 120.521688,
+ "avg": 34.237912579780634
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "checks": {
+ "passes": 111786,
+ "fails": 0,
+ "value": 1
+ },
+ "http_reqs": {
+ "count": 111882,
+ "rate": 3571.61243052309
+ },
+ "http_req_blocked": {
+ "p(50)": 0.001519,
+ "p(95)": 0.002553,
+ "p(99)": 0.003789190000000002,
+ "max": 49.856266,
+ "avg": 0.009302830580433014
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_waiting": {
+ "p(95)": 79.96578974999998,
+ "p(99)": 93.22801432000001,
+ "max": 120.408216,
+ "avg": 34.187562250183724,
+ "p(50)": 29.6369005
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "iterations": {
+ "count": 111786,
+ "rate": 3568.5478196533327
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 111882,
+ "value": 0
+ },
+ "http_req_sending": {
+ "avg": 0.008618359065801525,
+ "p(50)": 0.006162,
+ "p(95)": 0.01056,
+ "p(99)": 0.03366090000000002,
+ "max": 23.358321
+ },
+ "data_received": {
+ "count": 182683957,
+ "rate": 5831825.420338801
+ },
+ "http_req_duration": {
+ "max": 120.521688,
+ "avg": 34.237912579780634,
+ "p(50)": 29.695762000000002,
+ "p(95)": 80.00539605,
+ "p(99)": 93.26696904
+ },
+ "data_sent": {
+ "count": 31442702,
+ "rate": 1003746.3158723766
+ },
+ "http_req_connecting": {
+ "avg": 0.006500674165638799,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 31.373141
+ },
+ "http_req_receiving": {
+ "avg": 0.041731970531452514,
+ "p(50)": 0.024356,
+ "p(95)": 0.080015,
+ "p(99)": 0.22757449000000018,
+ "max": 43.041613
+ },
+ "iteration_duration": {
+ "avg": 34.34378399862206,
+ "p(50)": 29.820221,
+ "p(95)": 80.0930365,
+ "p(99)": 93.34415389999995,
+ "max": 120.617875
+ }
+ }
+}
diff --git a/evidence/track1/raw/f4x0.5-r1.json b/evidence/track1/raw/f4x0.5-r1.json
new file mode 100644
index 00000000..d04c6d49
--- /dev/null
+++ b/evidence/track1/raw/f4x0.5-r1.json
@@ -0,0 +1,64 @@
+{
+ "label": "f4x0.5-r1",
+ "config": "f4x0.5",
+ "series": "fixed",
+ "repeat": 1,
+ "replicas": 4,
+ "cpus_per_replica": "0.5",
+ "mem_per_replica": "128M",
+ "db_pool_per_replica": 5,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087209,
+ "instances": [
+ "0738ff1bbafe",
+ "302028ecf0c4",
+ "904b1d5c1d70",
+ "9c369463e99c"
+ ],
+ "rps": 2984.8,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 32.34,
+ "p(95)": 96.66,
+ "p(99)": 120.47,
+ "max": 256.78
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 188.6,
+ "cpu_pct_max_one_container": 52.7,
+ "mem_mib_mean": 82.1,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 40.0,
+ "cpu_pct_max_one_container": 45.5,
+ "mem_mib_mean": 33.7,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 143.9,
+ "cpu_pct_max_one_container": 169.2,
+ "mem_mib_mean": 258.1,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 7.6,
+ "cpu_pct_max_one_container": 8.8,
+ "mem_mib_mean": 6.9,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 9.2,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 6.94,
+ "IO:WalSync": 0.88,
+ "CPU:-": 0.75,
+ "Client:ClientRead": 0.69
+ }
+ }
+}
diff --git a/evidence/track1/raw/f4x0.5-r1.k6.json b/evidence/track1/raw/f4x0.5-r1.k6.json
new file mode 100644
index 00000000..079c3d38
--- /dev/null
+++ b/evidence/track1/raw/f4x0.5-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "checks": {
+ "get 200": {
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 28155,
+ "fails": 0,
+ "name": "get 200"
+ },
+ "post 201": {
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 65703,
+ "fails": 0,
+ "name": "post 201"
+ }
+ },
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {}
+ },
+ "metrics": {
+ "http_req_sending": {
+ "avg": 0.010553413734380727,
+ "p(50)": 0.006546,
+ "p(95)": 0.013423049999999973,
+ "p(99)": 0.038074880000000005,
+ "max": 38.405692
+ },
+ "http_reqs": {
+ "count": 93954,
+ "rate": 2984.764859334232
+ },
+ "http_req_duration": {
+ "max": 256.78066,
+ "avg": 40.824834922515436,
+ "p(50)": 32.344033499999995,
+ "p(95)": 96.65520274999996,
+ "p(99)": 120.46999923000001
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "iteration_duration": {
+ "max": 256.903214,
+ "avg": 40.944779177395915,
+ "p(50)": 32.4983345,
+ "p(95)": 96.74769194999996,
+ "p(99)": 120.58521561999952
+ },
+ "iterations": {
+ "count": 93858,
+ "rate": 2981.7150964024136
+ },
+ "data_received": {
+ "count": 152719825,
+ "rate": 4851658.971237771
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(95)": 96.65520274999996,
+ "p(99)": 120.46999923000001,
+ "max": 256.78066,
+ "avg": 40.824834922515436,
+ "p(50)": 32.344033499999995
+ },
+ "http_req_waiting": {
+ "avg": 40.770604317356835,
+ "p(50)": 32.287172999999996,
+ "p(95)": 96.57808924999999,
+ "p(99)": 120.38964313000002,
+ "max": 256.705537
+ },
+ "vus_max": {
+ "min": 128,
+ "max": 128,
+ "value": 128
+ },
+ "http_req_receiving": {
+ "avg": 0.04367719142346251,
+ "p(50)": 0.027266,
+ "p(95)": 0.08713804999999998,
+ "p(99)": 0.17886736000000011,
+ "max": 56.350275
+ },
+ "vus": {
+ "max": 128,
+ "value": 128,
+ "min": 0
+ },
+ "checks": {
+ "passes": 93858,
+ "fails": 0,
+ "value": 1
+ },
+ "data_sent": {
+ "count": 26417284,
+ "rate": 839233.8906513023
+ },
+ "http_req_connecting": {
+ "avg": 0.01280401793430828,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 38.13797
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 93954,
+ "value": 0
+ },
+ "http_req_blocked": {
+ "avg": 0.015714630542605572,
+ "p(50)": 0.001633,
+ "p(95)": 0.00267,
+ "p(99)": 0.003815470000000001,
+ "max": 38.168327
+ }
+ }
+}
diff --git a/evidence/track1/raw/f4x0.5-r2.json b/evidence/track1/raw/f4x0.5-r2.json
new file mode 100644
index 00000000..f4575448
--- /dev/null
+++ b/evidence/track1/raw/f4x0.5-r2.json
@@ -0,0 +1,64 @@
+{
+ "label": "f4x0.5-r2",
+ "config": "f4x0.5",
+ "series": "fixed",
+ "repeat": 2,
+ "replicas": 4,
+ "cpus_per_replica": "0.5",
+ "mem_per_replica": "128M",
+ "db_pool_per_replica": 5,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087381,
+ "instances": [
+ "52ea4e021106",
+ "5ee19ed9db31",
+ "666f41a587dd",
+ "a9c7278ae804"
+ ],
+ "rps": 3203.5,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 28.37,
+ "p(95)": 102.45,
+ "p(99)": 127.25,
+ "max": 179.39
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 187.3,
+ "cpu_pct_max_one_container": 53.2,
+ "mem_mib_mean": 81.6,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 42.4,
+ "cpu_pct_max_one_container": 51.6,
+ "mem_mib_mean": 34.1,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 152.8,
+ "cpu_pct_max_one_container": 174.7,
+ "mem_mib_mean": 346.9,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.1,
+ "cpu_pct_max_one_container": 9.5,
+ "mem_mib_mean": 7.1,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 12.8,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 10.94,
+ "IO:WalSync": 0.81,
+ "CPU:-": 0.81,
+ "Client:ClientRead": 0.19
+ }
+ }
+}
diff --git a/evidence/track1/raw/f4x0.5-r2.k6.json b/evidence/track1/raw/f4x0.5-r2.k6.json
new file mode 100644
index 00000000..31b24326
--- /dev/null
+++ b/evidence/track1/raw/f4x0.5-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 30160,
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200"
+ },
+ "post 201": {
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 70356,
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201"
+ }
+ },
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e"
+ },
+ "metrics": {
+ "http_req_waiting": {
+ "avg": 38.05820004944738,
+ "p(50)": 28.299620500000003,
+ "p(95)": 102.41979644999999,
+ "p(99)": 127.21221977999998,
+ "max": 179.363586
+ },
+ "http_req_connecting": {
+ "avg": 0.006642181071840338,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 26.453043
+ },
+ "iterations": {
+ "count": 100516,
+ "rate": 3200.4651958501327
+ },
+ "http_req_blocked": {
+ "p(50)": 0.001507,
+ "p(95)": 0.002574,
+ "p(99)": 0.0038017799999999985,
+ "max": 29.262907,
+ "avg": 0.009076375521806658
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_sending": {
+ "p(99)": 0.035070899999999995,
+ "max": 27.132647,
+ "avg": 0.009530304327515478,
+ "p(50)": 0.006212,
+ "p(95)": 0.011071449999999997
+ },
+ "data_sent": {
+ "count": 28290368,
+ "rate": 900775.3806537499
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 100612,
+ "value": 0
+ },
+ "http_reqs": {
+ "rate": 3203.521869999538,
+ "count": 100612
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(50)": 28.367493500000002,
+ "p(95)": 102.44973995,
+ "p(99)": 127.25356268999998,
+ "max": 179.393698,
+ "avg": 38.11100850145144
+ },
+ "http_req_duration": {
+ "p(95)": 102.44973995,
+ "p(99)": 127.25356268999998,
+ "max": 179.393698,
+ "avg": 38.11100850145144,
+ "p(50)": 28.367493500000002
+ },
+ "vus": {
+ "max": 128,
+ "value": 128,
+ "min": 0
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "http_req_receiving": {
+ "p(50)": 0.025147,
+ "p(95)": 0.08443154999999994,
+ "p(99)": 0.21561748,
+ "max": 54.910303,
+ "avg": 0.043278147676220985
+ },
+ "data_received": {
+ "count": 163573564,
+ "rate": 5208240.46463413
+ },
+ "checks": {
+ "passes": 100516,
+ "fails": 0,
+ "value": 1
+ },
+ "iteration_duration": {
+ "avg": 38.21619505985088,
+ "p(50)": 28.49306,
+ "p(95)": 102.54680025,
+ "p(99)": 127.34492440000002,
+ "max": 179.472263
+ }
+ }
+}
diff --git a/evidence/track1/raw/f4x0.5-r3.json b/evidence/track1/raw/f4x0.5-r3.json
new file mode 100644
index 00000000..3adbf4dc
--- /dev/null
+++ b/evidence/track1/raw/f4x0.5-r3.json
@@ -0,0 +1,64 @@
+{
+ "label": "f4x0.5-r3",
+ "config": "f4x0.5",
+ "series": "fixed",
+ "repeat": 3,
+ "replicas": 4,
+ "cpus_per_replica": "0.5",
+ "mem_per_replica": "128M",
+ "db_pool_per_replica": 5,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087558,
+ "instances": [
+ "49e988364d41",
+ "b80424873222",
+ "c4677f834163",
+ "cde95be1fe2f"
+ ],
+ "rps": 3142.4,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 33.31,
+ "p(95)": 90.95,
+ "p(99)": 118.0,
+ "max": 182.89
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 185.6,
+ "cpu_pct_max_one_container": 52.9,
+ "mem_mib_mean": 90.8,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 39.1,
+ "cpu_pct_max_one_container": 46.2,
+ "mem_mib_mean": 34.2,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 141.6,
+ "cpu_pct_max_one_container": 165.9,
+ "mem_mib_mean": 440.0,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 7.9,
+ "cpu_pct_max_one_container": 10.2,
+ "mem_mib_mean": 7.3,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 9.7,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 8.12,
+ "IO:WalSync": 0.88,
+ "CPU:-": 0.5,
+ "Client:ClientRead": 0.19
+ }
+ }
+}
diff --git a/evidence/track1/raw/f4x0.5-r3.k6.json b/evidence/track1/raw/f4x0.5-r3.k6.json
new file mode 100644
index 00000000..008b423a
--- /dev/null
+++ b/evidence/track1/raw/f4x0.5-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "passes": 29533,
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c"
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 69204,
+ "fails": 0
+ }
+ },
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e"
+ },
+ "metrics": {
+ "http_reqs": {
+ "count": 98833,
+ "rate": 3142.3694280959307
+ },
+ "vus": {
+ "min": 0,
+ "max": 128,
+ "value": 128
+ },
+ "http_req_connecting": {
+ "p(99)": 0,
+ "max": 36.310779,
+ "avg": 0.012060091538251392,
+ "p(50)": 0,
+ "p(95)": 0
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 38.78413502029701,
+ "p(50)": 33.308102,
+ "p(95)": 90.94796179999999,
+ "p(99)": 117.99936971999985,
+ "max": 182.888057
+ },
+ "iteration_duration": {
+ "p(50)": 33.463162,
+ "p(95)": 91.0330204,
+ "p(99)": 118.14931127999999,
+ "max": 182.930457,
+ "avg": 38.8995939527021
+ },
+ "http_req_receiving": {
+ "p(95)": 0.08499559999999995,
+ "p(99)": 0.16996935999999876,
+ "max": 57.650978,
+ "avg": 0.045087920158246635,
+ "p(50)": 0.026523
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "http_req_blocked": {
+ "p(95)": 0.002549399999999994,
+ "p(99)": 0.003703679999999993,
+ "max": 39.438942,
+ "avg": 0.01471246491556464,
+ "p(50)": 0.00155
+ },
+ "data_sent": {
+ "count": 27799069,
+ "rate": 883864.1400658617
+ },
+ "http_req_duration": {
+ "p(99)": 117.99936971999985,
+ "max": 182.888057,
+ "avg": 38.78413502029701,
+ "p(50)": 33.308102,
+ "p(95)": 90.94796179999999
+ },
+ "data_received": {
+ "count": 160192104,
+ "rate": 5093266.117915715
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 98833,
+ "value": 0
+ },
+ "iterations": {
+ "count": 98737,
+ "rate": 3139.3171331630924
+ },
+ "checks": {
+ "fails": 0,
+ "passes": 98737,
+ "value": 1
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_sending": {
+ "p(99)": 0.03839579999999993,
+ "max": 34.659442,
+ "avg": 0.008826450922262762,
+ "p(50)": 0.006275,
+ "p(95)": 0.01203399999999997
+ },
+ "http_req_waiting": {
+ "p(99)": 117.9732398399997,
+ "max": 182.874786,
+ "avg": 38.730220649216854,
+ "p(50)": 33.240377,
+ "p(95)": 90.90424939999998
+ }
+ }
+}
diff --git a/evidence/track1/raw/g1-r1.json b/evidence/track1/raw/g1-r1.json
new file mode 100644
index 00000000..4bd5fc76
--- /dev/null
+++ b/evidence/track1/raw/g1-r1.json
@@ -0,0 +1,61 @@
+{
+ "label": "g1-r1",
+ "config": "g1",
+ "series": "growth",
+ "repeat": 1,
+ "replicas": 1,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087627,
+ "instances": [
+ "1ee8ddfcabea"
+ ],
+ "rps": 2054.5,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 55.53,
+ "p(95)": 86.51,
+ "p(99)": 95.76,
+ "max": 117.43
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 92.5,
+ "cpu_pct_max_one_container": 104.0,
+ "mem_mib_mean": 29.9,
+ "containers": 1
+ },
+ "lb": {
+ "cpu_pct_mean": 21.5,
+ "cpu_pct_max_one_container": 25.4,
+ "mem_mib_mean": 33.5,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 80.1,
+ "cpu_pct_max_one_container": 94.7,
+ "mem_mib_mean": 414.7,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 3.9,
+ "cpu_pct_max_one_container": 4.4,
+ "mem_mib_mean": 6.7,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 5.3,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 4.19,
+ "IO:WalSync": 0.75,
+ "CPU:-": 0.19,
+ "Client:ClientRead": 0.19
+ }
+ }
+}
diff --git a/evidence/track1/raw/g1-r1.k6.json b/evidence/track1/raw/g1-r1.k6.json
new file mode 100644
index 00000000..b9317f85
--- /dev/null
+++ b/evidence/track1/raw/g1-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "checks": {
+ "post 201": {
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 44961,
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201"
+ },
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 19259,
+ "fails": 0
+ }
+ },
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {}
+ },
+ "metrics": {
+ "iterations": {
+ "count": 64220,
+ "rate": 2051.4060357604544
+ },
+ "http_req_sending": {
+ "max": 20.831091,
+ "avg": 0.008776248040923012,
+ "p(50)": 0.005947,
+ "p(95)": 0.0097765,
+ "p(99)": 0.031333849999999996
+ },
+ "checks": {
+ "passes": 64220,
+ "fails": 0,
+ "value": 1
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "data_sent": {
+ "rate": 573129.4016371976,
+ "count": 17942021
+ },
+ "data_received": {
+ "count": 104169953,
+ "rate": 3327543.9166783383
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(50)": 55.531501500000005,
+ "p(95)": 86.5051345,
+ "p(99)": 95.7562521,
+ "max": 117.430818,
+ "avg": 59.64970471478371
+ },
+ "http_req_connecting": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 35.848566,
+ "avg": 0.013197554512096523,
+ "p(50)": 0
+ },
+ "http_req_waiting": {
+ "avg": 59.609762551278,
+ "p(50)": 55.496461,
+ "p(95)": 86.46187925000001,
+ "p(99)": 95.70980759999999,
+ "max": 117.045433
+ },
+ "iteration_duration": {
+ "p(99)": 95.83652925999999,
+ "max": 144.916597,
+ "avg": 59.802421243507034,
+ "p(50)": 55.657302,
+ "p(95)": 86.57172025
+ },
+ "http_req_tls_handshaking": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0,
+ "avg": 0,
+ "p(50)": 0
+ },
+ "http_req_receiving": {
+ "avg": 0.03116591546426993,
+ "p(50)": 0.0233775,
+ "p(95)": 0.058679499999999996,
+ "p(99)": 0.13208174999999994,
+ "max": 44.978448
+ },
+ "http_req_blocked": {
+ "max": 38.576665,
+ "avg": 0.01570285425088632,
+ "p(50)": 0.001434,
+ "p(95)": 0.0023072500000000003,
+ "p(99)": 0.0033808499999999986
+ },
+ "http_req_failed": {
+ "fails": 64316,
+ "passes": 0,
+ "value": 0
+ },
+ "http_reqs": {
+ "count": 64316,
+ "rate": 2054.4726034875334
+ },
+ "http_req_duration": {
+ "p(99)": 95.7562521,
+ "max": 117.430818,
+ "avg": 59.64970471478371,
+ "p(50)": 55.531501500000005,
+ "p(95)": 86.5051345
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ }
+ }
+}
diff --git a/evidence/track1/raw/g1-r2.json b/evidence/track1/raw/g1-r2.json
new file mode 100644
index 00000000..e5a6a49d
--- /dev/null
+++ b/evidence/track1/raw/g1-r2.json
@@ -0,0 +1,61 @@
+{
+ "label": "g1-r2",
+ "config": "g1",
+ "series": "growth",
+ "repeat": 2,
+ "replicas": 1,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087859,
+ "instances": [
+ "285e72edd31b"
+ ],
+ "rps": 2065.0,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 54.78,
+ "p(95)": 86.58,
+ "p(99)": 94.74,
+ "max": 111.69
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 95.9,
+ "cpu_pct_max_one_container": 102.0,
+ "mem_mib_mean": 29.2,
+ "containers": 1
+ },
+ "lb": {
+ "cpu_pct_mean": 21.3,
+ "cpu_pct_max_one_container": 23.5,
+ "mem_mib_mean": 33.7,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 85.1,
+ "cpu_pct_max_one_container": 93.5,
+ "mem_mib_mean": 459.6,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 4.9,
+ "cpu_pct_max_one_container": 6.1,
+ "mem_mib_mean": 6.8,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 5.2,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 4.12,
+ "IO:WalSync": 0.69,
+ "CPU:-": 0.38,
+ "Client:ClientRead": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/g1-r2.k6.json b/evidence/track1/raw/g1-r2.k6.json
new file mode 100644
index 00000000..c5a8fc4f
--- /dev/null
+++ b/evidence/track1/raw/g1-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 64761,
+ "value": 0
+ },
+ "http_req_waiting": {
+ "p(95)": 86.545216,
+ "p(99)": 94.6965052,
+ "max": 111.673468,
+ "avg": 59.22336671363986,
+ "p(50)": 54.741914
+ },
+ "http_reqs": {
+ "count": 64761,
+ "rate": 2065.0306546565535
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 59.26636343679062,
+ "p(50)": 54.780086,
+ "p(95)": 86.581343,
+ "p(99)": 94.744448,
+ "max": 111.688511
+ },
+ "http_req_receiving": {
+ "avg": 0.033951737063973975,
+ "p(50)": 0.024023,
+ "p(95)": 0.058554,
+ "p(99)": 0.13663600000000004,
+ "max": 36.045367
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "data_sent": {
+ "count": 18045628,
+ "rate": 575420.0059067747
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_connecting": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 48.933986,
+ "avg": 0.02071342042278532,
+ "p(50)": 0
+ },
+ "checks": {
+ "passes": 64665,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_blocked": {
+ "avg": 0.024769287626812714,
+ "p(50)": 0.001468,
+ "p(95)": 0.00235,
+ "p(99)": 0.0034752000000000042,
+ "max": 49.156439
+ },
+ "http_req_duration": {
+ "avg": 59.26636343679062,
+ "p(50)": 54.780086,
+ "p(95)": 86.581343,
+ "p(99)": 94.744448,
+ "max": 111.688511
+ },
+ "http_req_sending": {
+ "avg": 0.009044986087305574,
+ "p(50)": 0.006039,
+ "p(95)": 0.010038,
+ "p(99)": 0.03133680000000002,
+ "max": 3.97227
+ },
+ "iteration_duration": {
+ "p(99)": 94.83881532,
+ "max": 111.73765,
+ "avg": 59.43006596104569,
+ "p(50)": 54.896285,
+ "p(95)": 86.68669779999999
+ },
+ "data_received": {
+ "count": 105803791,
+ "rate": 3373760.0066996366
+ },
+ "iterations": {
+ "count": 64665,
+ "rate": 2061.969507625979
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ }
+ },
+ "root_group": {
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 19592,
+ "fails": 0
+ },
+ "post 201": {
+ "passes": 45073,
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9"
+ }
+ },
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e"
+ }
+}
diff --git a/evidence/track1/raw/g1-r3.json b/evidence/track1/raw/g1-r3.json
new file mode 100644
index 00000000..2c32a70f
--- /dev/null
+++ b/evidence/track1/raw/g1-r3.json
@@ -0,0 +1,61 @@
+{
+ "label": "g1-r3",
+ "config": "g1",
+ "series": "growth",
+ "repeat": 3,
+ "replicas": 1,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088094,
+ "instances": [
+ "a1d3c24bcdd7"
+ ],
+ "rps": 2033.3,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 56.02,
+ "p(95)": 87.3,
+ "p(99)": 94.59,
+ "max": 174.6
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 97.2,
+ "cpu_pct_max_one_container": 104.0,
+ "mem_mib_mean": 27.0,
+ "containers": 1
+ },
+ "lb": {
+ "cpu_pct_mean": 22.5,
+ "cpu_pct_max_one_container": 25.5,
+ "mem_mib_mean": 33.7,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 81.6,
+ "cpu_pct_max_one_container": 93.4,
+ "mem_mib_mean": 519.1,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 3.9,
+ "cpu_pct_max_one_container": 4.5,
+ "mem_mib_mean": 6.7,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 6.2,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 4.75,
+ "IO:WalSync": 0.75,
+ "CPU:-": 0.69,
+ "Client:ClientRead": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/g1-r3.k6.json b/evidence/track1/raw/g1-r3.k6.json
new file mode 100644
index 00000000..297c662b
--- /dev/null
+++ b/evidence/track1/raw/g1-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "checks": {
+ "post 201": {
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 44724,
+ "fails": 0,
+ "name": "post 201"
+ },
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 18866,
+ "fails": 0
+ }
+ },
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {}
+ },
+ "metrics": {
+ "data_sent": {
+ "count": 17786830,
+ "rate": 567873.0878250012
+ },
+ "iterations": {
+ "count": 63590,
+ "rate": 2030.2127841100312
+ },
+ "http_reqs": {
+ "count": 63686,
+ "rate": 2033.277738148002
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 63686,
+ "value": 0
+ },
+ "http_req_waiting": {
+ "p(50)": 55.979135,
+ "p(95)": 87.26442875000001,
+ "p(99)": 94.56105225,
+ "max": 174.569016,
+ "avg": 60.18197730727374
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 60.22306867669504,
+ "p(50)": 56.0208985,
+ "p(95)": 87.296864,
+ "p(99)": 94.59037860000001,
+ "max": 174.595923
+ },
+ "http_req_blocked": {
+ "max": 63.631048,
+ "avg": 0.02574174743271755,
+ "p(50)": 0.00144,
+ "p(95)": 0.002333,
+ "p(99)": 0.003333300000000003
+ },
+ "http_req_sending": {
+ "avg": 0.008831947366768277,
+ "p(50)": 0.006019,
+ "p(95)": 0.009893,
+ "p(99)": 0.03167190000000001,
+ "max": 40.376018
+ },
+ "http_req_duration": {
+ "avg": 60.22306867669504,
+ "p(50)": 56.0208985,
+ "p(95)": 87.296864,
+ "p(99)": 94.59037860000001,
+ "max": 174.595923
+ },
+ "checks": {
+ "passes": 63590,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_connecting": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 63.582494,
+ "avg": 0.023136772226234965,
+ "p(50)": 0
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "iteration_duration": {
+ "avg": 60.3922966116365,
+ "p(50)": 56.189633,
+ "p(95)": 87.39810309999999,
+ "p(99)": 94.66374853,
+ "max": 174.655673
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_receiving": {
+ "p(95)": 0.0596985,
+ "p(99)": 0.13124635000000007,
+ "max": 37.443302,
+ "avg": 0.03225942205508254,
+ "p(50)": 0.0237445
+ },
+ "data_received": {
+ "count": 102521115,
+ "rate": 3273151.0978804007
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-oneshot-r1.json b/evidence/track1/raw/g2-oneshot-r1.json
new file mode 100644
index 00000000..de7d4c0a
--- /dev/null
+++ b/evidence/track1/raw/g2-oneshot-r1.json
@@ -0,0 +1,65 @@
+{
+ "label": "g2-oneshot-r1",
+ "config": "g2-oneshot",
+ "series": "growth",
+ "repeat": 1,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "oneshot"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088532,
+ "instances": [
+ "58b72b0ae9a2",
+ "d5e1349ca0b7"
+ ],
+ "rps": 4680.8,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 23.32,
+ "p(95)": 58.36,
+ "p(99)": 73.28,
+ "max": 118.81
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 169.2,
+ "cpu_pct_max_one_container": 95.3,
+ "mem_mib_mean": 48.3,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 57.7,
+ "cpu_pct_max_one_container": 67.0,
+ "mem_mib_mean": 34.7,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 184.7,
+ "cpu_pct_max_one_container": 204.9,
+ "mem_mib_mean": 578.2,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 10.5,
+ "cpu_pct_max_one_container": 12.2,
+ "mem_mib_mean": 7.0,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 17.8,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 15.5,
+ "CPU:-": 1.19,
+ "IO:WalSync": 0.94,
+ "Client:ClientRead": 0.12
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-oneshot-r1.k6.json b/evidence/track1/raw/g2-oneshot-r1.k6.json
new file mode 100644
index 00000000..45c89864
--- /dev/null
+++ b/evidence/track1/raw/g2-oneshot-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "checks": {
+ "passes": 146730,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_sending": {
+ "avg": 0.008301080108427623,
+ "p(50)": 0.006416,
+ "p(95)": 0.010744749999999999,
+ "p(99)": 0.03342225,
+ "max": 32.333
+ },
+ "http_req_receiving": {
+ "avg": 0.035131107814692385,
+ "p(50)": 0.025328,
+ "p(95)": 0.076794,
+ "p(99)": 0.21385225000000002,
+ "max": 18.1596
+ },
+ "iterations": {
+ "count": 146730,
+ "rate": 4677.736733732591
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "vus": {
+ "max": 128,
+ "value": 128,
+ "min": 0
+ },
+ "http_reqs": {
+ "count": 146826,
+ "rate": 4680.7972034827335
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(50)": 23.316463,
+ "p(95)": 58.36315675,
+ "p(99)": 73.28232275,
+ "max": 118.808024,
+ "avg": 26.072770195455973
+ },
+ "http_req_blocked": {
+ "avg": 0.005610603796330362,
+ "p(50)": 0.001623,
+ "p(95)": 0.002647,
+ "p(99)": 0.0039065,
+ "max": 35.329839
+ },
+ "http_req_tls_handshaking": {
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0,
+ "avg": 0
+ },
+ "data_received": {
+ "count": 238808475,
+ "rate": 7613188.685573238
+ },
+ "http_req_waiting": {
+ "p(50)": 23.272432000000002,
+ "p(95)": 58.3038215,
+ "p(99)": 73.2361635,
+ "max": 118.760873,
+ "avg": 26.029338007532616
+ },
+ "http_req_connecting": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 35.303615,
+ "avg": 0.0029429335199487837,
+ "p(50)": 0
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 146826,
+ "value": 0
+ },
+ "data_sent": {
+ "count": 41020063,
+ "rate": 1307715.2287543456
+ },
+ "iteration_duration": {
+ "avg": 26.159670379616,
+ "p(50)": 23.418589,
+ "p(95)": 58.45516539999998,
+ "p(99)": 73.35752381999997,
+ "max": 118.877711
+ },
+ "http_req_duration": {
+ "avg": 26.072770195455973,
+ "p(50)": 23.316463,
+ "p(95)": 58.36315675,
+ "p(99)": 73.28232275,
+ "max": 118.808024
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 102769,
+ "fails": 0
+ },
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 43961,
+ "fails": 0
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-oneshot-r2.json b/evidence/track1/raw/g2-oneshot-r2.json
new file mode 100644
index 00000000..2faf118b
--- /dev/null
+++ b/evidence/track1/raw/g2-oneshot-r2.json
@@ -0,0 +1,65 @@
+{
+ "label": "g2-oneshot-r2",
+ "config": "g2-oneshot",
+ "series": "growth",
+ "repeat": 2,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "oneshot"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088791,
+ "instances": [
+ "7b3daeee8dce",
+ "9ac0c5963c46"
+ ],
+ "rps": 4452.8,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 24.06,
+ "p(95)": 64.08,
+ "p(99)": 78.96,
+ "max": 134.69
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 173.6,
+ "cpu_pct_max_one_container": 97.0,
+ "mem_mib_mean": 56.0,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 58.4,
+ "cpu_pct_max_one_container": 65.7,
+ "mem_mib_mean": 34.7,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 187.3,
+ "cpu_pct_max_one_container": 209.6,
+ "mem_mib_mean": 587.1,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 10.8,
+ "cpu_pct_max_one_container": 12.3,
+ "mem_mib_mean": 6.8,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 16.4,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 13.81,
+ "CPU:-": 1.56,
+ "IO:WalSync": 0.94,
+ "Client:ClientRead": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-oneshot-r2.k6.json b/evidence/track1/raw/g2-oneshot-r2.k6.json
new file mode 100644
index 00000000..a3c2fdec
--- /dev/null
+++ b/evidence/track1/raw/g2-oneshot-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 41809,
+ "fails": 0
+ },
+ "post 201": {
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 98056
+ }
+ },
+ "name": ""
+ },
+ "metrics": {
+ "iterations": {
+ "count": 139865,
+ "rate": 4449.773164613472
+ },
+ "http_req_blocked": {
+ "max": 30.569044,
+ "avg": 0.010051601467551356,
+ "p(50)": 0.001824,
+ "p(95)": 0.002932,
+ "p(99)": 0.004227
+ },
+ "checks": {
+ "passes": 139865,
+ "fails": 0,
+ "value": 1
+ },
+ "iteration_duration": {
+ "p(50)": 24.178312,
+ "p(95)": 64.16327839999998,
+ "p(99)": 79.02659167999987,
+ "max": 134.794827,
+ "avg": 27.44668781601534
+ },
+ "http_req_failed": {
+ "fails": 139961,
+ "passes": 0,
+ "value": 0
+ },
+ "http_req_sending": {
+ "p(99)": 0.03667919999999946,
+ "max": 31.152476,
+ "avg": 0.009838847043104898,
+ "p(50)": 0.006992,
+ "p(95)": 0.012389
+ },
+ "http_req_connecting": {
+ "avg": 0.006997742735476313,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 29.820358
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 27.345733756768013,
+ "p(50)": 24.061417,
+ "p(95)": 64.081035,
+ "p(99)": 78.96403899999994,
+ "max": 134.688879
+ },
+ "http_req_duration": {
+ "p(50)": 24.061417,
+ "p(95)": 64.081035,
+ "p(99)": 78.96403899999994,
+ "max": 134.688879,
+ "avg": 27.345733756768013
+ },
+ "http_req_waiting": {
+ "avg": 27.2981252557429,
+ "p(50)": 24.017689,
+ "p(95)": 64.034439,
+ "p(99)": 78.89333119999999,
+ "max": 134.600354
+ },
+ "http_reqs": {
+ "count": 139961,
+ "rate": 4452.827382779581
+ },
+ "http_req_receiving": {
+ "p(99)": 0.23073039999999903,
+ "max": 14.142265,
+ "avg": 0.03776965398218043,
+ "p(50)": 0.027648,
+ "p(95)": 0.082367
+ },
+ "http_req_tls_handshaking": {
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0,
+ "avg": 0
+ },
+ "vus_max": {
+ "min": 128,
+ "max": 128,
+ "value": 128
+ },
+ "data_sent": {
+ "count": 39102685,
+ "rate": 1244043.029902647
+ },
+ "data_received": {
+ "count": 227277236,
+ "rate": 7230773.572232673
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-oneshot-r3.json b/evidence/track1/raw/g2-oneshot-r3.json
new file mode 100644
index 00000000..9e4df613
--- /dev/null
+++ b/evidence/track1/raw/g2-oneshot-r3.json
@@ -0,0 +1,66 @@
+{
+ "label": "g2-oneshot-r3",
+ "config": "g2-oneshot",
+ "series": "growth",
+ "repeat": 3,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "oneshot"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792089048,
+ "instances": [
+ "3bb894084811",
+ "d5bbb713c4b7"
+ ],
+ "rps": 4604.7,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 23.34,
+ "p(95)": 61.76,
+ "p(99)": 77.3,
+ "max": 130.85
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 154.3,
+ "cpu_pct_max_one_container": 97.5,
+ "mem_mib_mean": 54.5,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 52.0,
+ "cpu_pct_max_one_container": 67.2,
+ "mem_mib_mean": 34.6,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 165.5,
+ "cpu_pct_max_one_container": 211.2,
+ "mem_mib_mean": 583.4,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 10.4,
+ "cpu_pct_max_one_container": 13.9,
+ "mem_mib_mean": 7.1,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 17,
+ "active_backends_mean": 15.0,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 11.35,
+ "CPU:-": 1.94,
+ "IO:WalSync": 0.88,
+ "Client:ClientRead": 0.76,
+ "IO:DataFileExtend": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-oneshot-r3.k6.json b/evidence/track1/raw/g2-oneshot-r3.k6.json
new file mode 100644
index 00000000..44a94ef1
--- /dev/null
+++ b/evidence/track1/raw/g2-oneshot-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 43071,
+ "fails": 0
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 101262,
+ "fails": 0
+ }
+ }
+ },
+ "metrics": {
+ "http_req_connecting": {
+ "avg": 0.0029107481599955683,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 25.917897
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 26.519914660303552,
+ "p(50)": 23.33622,
+ "p(95)": 61.76125860000001,
+ "p(99)": 77.30414404,
+ "max": 130.849756
+ },
+ "data_sent": {
+ "rate": 1286912.9098319197,
+ "count": 40365165
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 144429,
+ "value": 0
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "http_req_sending": {
+ "p(99)": 0.034479880000000004,
+ "max": 26.015749,
+ "avg": 0.010551984490649575,
+ "p(50)": 0.006531,
+ "p(95)": 0.010999
+ },
+ "http_req_receiving": {
+ "avg": 0.0353814259047695,
+ "p(50)": 0.026002,
+ "p(95)": 0.07689260000000003,
+ "p(99)": 0.21501036000000015,
+ "max": 18.189112
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "iterations": {
+ "count": 144333,
+ "rate": 4601.591521173528
+ },
+ "http_req_duration": {
+ "p(99)": 77.30414404,
+ "max": 130.849756,
+ "avg": 26.519914660303552,
+ "p(50)": 23.33622,
+ "p(95)": 61.76125860000001
+ },
+ "data_received": {
+ "count": 234291014,
+ "rate": 7469612.240510129
+ },
+ "http_req_blocked": {
+ "avg": 0.005751773805814751,
+ "p(50)": 0.001684,
+ "p(95)": 0.002715,
+ "p(99)": 0.003911720000000001,
+ "max": 26.129524
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "http_reqs": {
+ "count": 144429,
+ "rate": 4604.652171101353
+ },
+ "http_req_waiting": {
+ "avg": 26.473981249907958,
+ "p(50)": 23.2847,
+ "p(95)": 61.716459400000005,
+ "p(99)": 77.26304624000001,
+ "max": 130.826241
+ },
+ "checks": {
+ "passes": 144333,
+ "fails": 0,
+ "value": 1
+ },
+ "iteration_duration": {
+ "p(99)": 77.38491047999999,
+ "max": 130.896776,
+ "avg": 26.609553634331377,
+ "p(50)": 23.445782,
+ "p(95)": 61.84249119999999
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-r1.json b/evidence/track1/raw/g2-r1.json
new file mode 100644
index 00000000..fff4ba33
--- /dev/null
+++ b/evidence/track1/raw/g2-r1.json
@@ -0,0 +1,63 @@
+{
+ "label": "g2-r1",
+ "config": "g2",
+ "series": "growth",
+ "repeat": 1,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087684,
+ "instances": [
+ "30fcf015f3a9",
+ "7470bc71cd74"
+ ],
+ "rps": 3563.8,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 30.76,
+ "p(95)": 74.76,
+ "p(99)": 86.67,
+ "max": 115.86
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 188.8,
+ "cpu_pct_max_one_container": 104.6,
+ "mem_mib_mean": 53.9,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 44.7,
+ "cpu_pct_max_one_container": 50.5,
+ "mem_mib_mean": 34.2,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 162.9,
+ "cpu_pct_max_one_container": 182.0,
+ "mem_mib_mean": 452.6,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.0,
+ "cpu_pct_max_one_container": 9.8,
+ "mem_mib_mean": 6.8,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 10.5,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 9.06,
+ "IO:WalSync": 0.88,
+ "CPU:-": 0.31,
+ "Client:ClientRead": 0.19,
+ "IO:DataFileRead": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-r1.k6.json b/evidence/track1/raw/g2-r1.k6.json
new file mode 100644
index 00000000..df41fdfb
--- /dev/null
+++ b/evidence/track1/raw/g2-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 33604,
+ "fails": 0
+ },
+ "post 201": {
+ "passes": 77963,
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9"
+ }
+ }
+ },
+ "metrics": {
+ "http_req_connecting": {
+ "avg": 0.011244924191540617,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 31.067331
+ },
+ "vus": {
+ "max": 128,
+ "value": 128,
+ "min": 0
+ },
+ "data_sent": {
+ "rate": 994241.0024633956,
+ "count": 31152514
+ },
+ "http_req_waiting": {
+ "avg": 34.252232173665604,
+ "p(50)": 30.699336,
+ "p(95)": 74.718053,
+ "p(99)": 86.62994934,
+ "max": 115.836355
+ },
+ "http_req_failed": {
+ "fails": 111663,
+ "passes": 0,
+ "value": 0
+ },
+ "http_req_tls_handshaking": {
+ "p(99)": 0,
+ "max": 0,
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0
+ },
+ "http_req_sending": {
+ "p(50)": 0.006245,
+ "p(95)": 0.010770899999999993,
+ "p(99)": 0.03628790000000002,
+ "max": 6.31949,
+ "avg": 0.010787817450722341
+ },
+ "vus_max": {
+ "max": 128,
+ "value": 128,
+ "min": 128
+ },
+ "http_reqs": {
+ "count": 111663,
+ "rate": 3563.755177449568
+ },
+ "http_req_blocked": {
+ "p(95)": 0.002579,
+ "p(99)": 0.003687380000000005,
+ "max": 63.404344,
+ "avg": 0.014301740630289788,
+ "p(50)": 0.001559
+ },
+ "iterations": {
+ "count": 111567,
+ "rate": 3560.6913111999133
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 34.30374821276541,
+ "p(50)": 30.761241,
+ "p(95)": 74.75609889999997,
+ "p(99)": 86.66834340000001,
+ "max": 115.862586
+ },
+ "http_req_receiving": {
+ "p(95)": 0.07911879999999999,
+ "p(99)": 0.18469654000000013,
+ "max": 43.208683,
+ "avg": 0.04072822164906886,
+ "p(50)": 0.025433
+ },
+ "http_req_duration": {
+ "max": 115.862586,
+ "avg": 34.30374821276541,
+ "p(50)": 30.761241,
+ "p(95)": 74.75609889999997,
+ "p(99)": 86.66834340000001
+ },
+ "data_received": {
+ "count": 182060194,
+ "rate": 5810500.872938868
+ },
+ "iteration_duration": {
+ "max": 115.924954,
+ "avg": 34.41240312254571,
+ "p(50)": 30.904651,
+ "p(95)": 74.8511204,
+ "p(99)": 86.75825505999998
+ },
+ "checks": {
+ "passes": 111567,
+ "fails": 0,
+ "value": 1
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-r2.json b/evidence/track1/raw/g2-r2.json
new file mode 100644
index 00000000..5814d932
--- /dev/null
+++ b/evidence/track1/raw/g2-r2.json
@@ -0,0 +1,62 @@
+{
+ "label": "g2-r2",
+ "config": "g2",
+ "series": "growth",
+ "repeat": 2,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087916,
+ "instances": [
+ "0460937e5887",
+ "8eacc6329aa0"
+ ],
+ "rps": 3264.1,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 33.35,
+ "p(95)": 74.35,
+ "p(99)": 85.88,
+ "max": 635.35
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 183.3,
+ "cpu_pct_max_one_container": 103.4,
+ "mem_mib_mean": 50.9,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 42.4,
+ "cpu_pct_max_one_container": 49.4,
+ "mem_mib_mean": 34.4,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 155.4,
+ "cpu_pct_max_one_container": 180.3,
+ "mem_mib_mean": 544.4,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 7.8,
+ "cpu_pct_max_one_container": 10.0,
+ "mem_mib_mean": 6.8,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 9.2,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 7.25,
+ "IO:WalSync": 0.94,
+ "CPU:-": 0.81,
+ "Client:ClientRead": 0.19
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-r2.k6.json b/evidence/track1/raw/g2-r2.k6.json
new file mode 100644
index 00000000..3a3572ef
--- /dev/null
+++ b/evidence/track1/raw/g2-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "http_req_connecting": {
+ "avg": 0.007795108200433346,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 37.016209
+ },
+ "iterations": {
+ "count": 102362,
+ "rate": 3260.992314847013
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_waiting": {
+ "p(50)": 33.289125999999996,
+ "p(95)": 74.30736429999999,
+ "p(99)": 85.84409269,
+ "max": 635.313784,
+ "avg": 37.358731956528274
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 102458,
+ "value": 0
+ },
+ "http_req_blocked": {
+ "p(50)": 0.001893,
+ "p(95)": 0.002859,
+ "p(99)": 0.003990859999999986,
+ "max": 53.968318,
+ "avg": 0.016196515206230385
+ },
+ "http_req_sending": {
+ "p(50)": 0.007265,
+ "p(95)": 0.015298899999999966,
+ "p(99)": 0.03663000999999995,
+ "max": 2.249934,
+ "avg": 0.009088734984091342
+ },
+ "iteration_duration": {
+ "max": 635.425711,
+ "avg": 37.526806351643735,
+ "p(50)": 33.471096,
+ "p(95)": 74.46488319999999,
+ "p(99)": 86.00342778
+ },
+ "http_req_receiving": {
+ "max": 46.814725,
+ "avg": 0.04048764102363869,
+ "p(50)": 0.028977,
+ "p(95)": 0.08270474999999997,
+ "p(99)": 0.15136120999999966
+ },
+ "http_reqs": {
+ "count": 102458,
+ "rate": 3264.0506300638444
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "data_received": {
+ "count": 167524633,
+ "rate": 5336907.648937753
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 37.40830833253622,
+ "p(50)": 33.345240000000004,
+ "p(95)": 74.34704404999998,
+ "p(99)": 85.88307832,
+ "max": 635.354405
+ },
+ "data_sent": {
+ "count": 28569143,
+ "rate": 910140.0496743453
+ },
+ "checks": {
+ "passes": 102362,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_duration": {
+ "p(99)": 85.88307832,
+ "max": 635.354405,
+ "avg": 37.40830833253622,
+ "p(50)": 33.345240000000004,
+ "p(95)": 74.34704404999998
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ }
+ },
+ "root_group": {
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 30959,
+ "fails": 0
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 71403,
+ "fails": 0
+ }
+ },
+ "name": "",
+ "path": ""
+ }
+}
diff --git a/evidence/track1/raw/g2-r3.json b/evidence/track1/raw/g2-r3.json
new file mode 100644
index 00000000..ce9c7ea5
--- /dev/null
+++ b/evidence/track1/raw/g2-r3.json
@@ -0,0 +1,62 @@
+{
+ "label": "g2-r3",
+ "config": "g2",
+ "series": "growth",
+ "repeat": 3,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088151,
+ "instances": [
+ "6ca19301d4ff",
+ "a4ef124aaa61"
+ ],
+ "rps": 3491.5,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 30.46,
+ "p(95)": 81.22,
+ "p(99)": 92.86,
+ "max": 129.64
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 192.4,
+ "cpu_pct_max_one_container": 106.7,
+ "mem_mib_mean": 49.9,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 44.7,
+ "cpu_pct_max_one_container": 49.6,
+ "mem_mib_mean": 34.3,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 165.5,
+ "cpu_pct_max_one_container": 185.6,
+ "mem_mib_mean": 542.9,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.1,
+ "cpu_pct_max_one_container": 9.9,
+ "mem_mib_mean": 6.7,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 8.2,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 6.88,
+ "IO:WalSync": 0.56,
+ "CPU:-": 0.5,
+ "Client:ClientRead": 0.25
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-r3.k6.json b/evidence/track1/raw/g2-r3.k6.json
new file mode 100644
index 00000000..c4e05ba4
--- /dev/null
+++ b/evidence/track1/raw/g2-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 32698,
+ "fails": 0,
+ "name": "get 200"
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 76611,
+ "fails": 0
+ }
+ }
+ },
+ "metrics": {
+ "http_reqs": {
+ "count": 109405,
+ "rate": 3491.486946776143
+ },
+ "http_req_waiting": {
+ "avg": 34.97016359993628,
+ "p(50)": 30.410192,
+ "p(95)": 81.1790176,
+ "p(99)": 92.83786223999999,
+ "max": 129.602176
+ },
+ "iteration_duration": {
+ "avg": 35.121474925294685,
+ "p(50)": 30.581348,
+ "p(95)": 81.3032212,
+ "p(99)": 92.94767031999994,
+ "max": 129.719516
+ },
+ "http_req_connecting": {
+ "avg": 0.006145812915314659,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 34.259764
+ },
+ "http_req_sending": {
+ "p(99)": 0.03386279999999996,
+ "max": 22.734737,
+ "avg": 0.010800808025227114,
+ "p(50)": 0.006246,
+ "p(95)": 0.010843
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "data_received": {
+ "count": 177460378,
+ "rate": 5663366.330213063
+ },
+ "iterations": {
+ "count": 109309,
+ "rate": 3488.423259130327
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 109405,
+ "value": 0
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "vus_max": {
+ "min": 128,
+ "max": 128,
+ "value": 128
+ },
+ "http_req_receiving": {
+ "avg": 0.03860670143046528,
+ "p(50)": 0.024996,
+ "p(95)": 0.08160019999999961,
+ "p(99)": 0.2274201599999988,
+ "max": 47.270457
+ },
+ "data_sent": {
+ "rate": 974796.5397534762,
+ "count": 30545042
+ },
+ "checks": {
+ "passes": 109309,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_duration": {
+ "avg": 35.01957110939168,
+ "p(50)": 30.45731,
+ "p(95)": 81.22156559999999,
+ "p(99)": 92.86225911999998,
+ "max": 129.642531
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 35.01957110939168,
+ "p(50)": 30.45731,
+ "p(95)": 81.22156559999999,
+ "p(99)": 92.86225911999998,
+ "max": 129.642531
+ },
+ "http_req_blocked": {
+ "max": 38.815941,
+ "avg": 0.009292588382615206,
+ "p(50)": 0.001557,
+ "p(95)": 0.002613,
+ "p(99)": 0.003826959999999992
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-tx-r1.json b/evidence/track1/raw/g2-tx-r1.json
new file mode 100644
index 00000000..ca53b992
--- /dev/null
+++ b/evidence/track1/raw/g2-tx-r1.json
@@ -0,0 +1,65 @@
+{
+ "label": "g2-tx-r1",
+ "config": "g2-tx",
+ "series": "growth",
+ "repeat": 1,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "tx"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088405,
+ "instances": [
+ "23fbf9195424",
+ "9a2864faa602"
+ ],
+ "rps": 3373.6,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 31.53,
+ "p(95)": 81.3,
+ "p(99)": 93.0,
+ "max": 238.59
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 193.2,
+ "cpu_pct_max_one_container": 105.3,
+ "mem_mib_mean": 50.6,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 43.9,
+ "cpu_pct_max_one_container": 49.3,
+ "mem_mib_mean": 34.4,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 167.5,
+ "cpu_pct_max_one_container": 184.4,
+ "mem_mib_mean": 544.0,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.2,
+ "cpu_pct_max_one_container": 10.0,
+ "mem_mib_mean": 6.8,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 8.4,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 6.75,
+ "IO:WalSync": 0.81,
+ "CPU:-": 0.56,
+ "Client:ClientRead": 0.25
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-tx-r1.k6.json b/evidence/track1/raw/g2-tx-r1.k6.json
new file mode 100644
index 00000000..1c421f44
--- /dev/null
+++ b/evidence/track1/raw/g2-tx-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 31745,
+ "fails": 0
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 74148,
+ "fails": 0
+ }
+ },
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {}
+ },
+ "metrics": {
+ "http_req_duration": {
+ "p(95)": 81.30416220000001,
+ "p(99)": 92.99833751999998,
+ "max": 238.593119,
+ "avg": 36.1612821651961,
+ "p(50)": 31.527476
+ },
+ "http_req_blocked": {
+ "p(50)": 0.001705,
+ "p(95)": 0.002754,
+ "p(99)": 0.0038851199999999954,
+ "max": 24.409047,
+ "avg": 0.01056808257460691
+ },
+ "http_req_sending": {
+ "p(99)": 0.035722519999999904,
+ "max": 2.916605,
+ "avg": 0.008974411872930134,
+ "p(50)": 0.006663,
+ "p(95)": 0.012108199999999982
+ },
+ "http_req_receiving": {
+ "p(99)": 0.1916627599999992,
+ "max": 53.339894,
+ "avg": 0.038890146354809974,
+ "p(50)": 0.027168,
+ "p(95)": 0.08188919999999994
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 105989,
+ "value": 0
+ },
+ "http_req_tls_handshaking": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0,
+ "avg": 0,
+ "p(50)": 0
+ },
+ "http_req_waiting": {
+ "avg": 36.11341760696839,
+ "p(50)": 31.484894,
+ "p(95)": 81.26190519999999,
+ "p(99)": 92.956242,
+ "max": 238.563275
+ },
+ "iterations": {
+ "count": 105893,
+ "rate": 3370.5785380066086
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 36.1612821651961,
+ "p(50)": 31.527476,
+ "p(95)": 81.30416220000001,
+ "p(99)": 92.99833751999998,
+ "max": 238.593119
+ },
+ "http_reqs": {
+ "count": 105989,
+ "rate": 3373.634221948405
+ },
+ "iteration_duration": {
+ "avg": 36.26873121603894,
+ "p(50)": 31.655034,
+ "p(95)": 81.38665599999999,
+ "p(99)": 93.09189692000002,
+ "max": 238.666761
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "checks": {
+ "passes": 105893,
+ "fails": 0,
+ "value": 1
+ },
+ "data_sent": {
+ "count": 29583299,
+ "rate": 941637.6218714397
+ },
+ "http_req_connecting": {
+ "avg": 0.00836636574550189,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 24.358107
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "data_received": {
+ "count": 172161599,
+ "rate": 5479910.765190334
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-tx-r2.json b/evidence/track1/raw/g2-tx-r2.json
new file mode 100644
index 00000000..858bff1e
--- /dev/null
+++ b/evidence/track1/raw/g2-tx-r2.json
@@ -0,0 +1,65 @@
+{
+ "label": "g2-tx-r2",
+ "config": "g2-tx",
+ "series": "growth",
+ "repeat": 2,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "tx"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088661,
+ "instances": [
+ "1ebcc4f1619d",
+ "64ec070d09a3"
+ ],
+ "rps": 3379.0,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 32.45,
+ "p(95)": 73.4,
+ "p(99)": 83.97,
+ "max": 140.87
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 191.4,
+ "cpu_pct_max_one_container": 104.4,
+ "mem_mib_mean": 53.7,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 43.6,
+ "cpu_pct_max_one_container": 48.8,
+ "mem_mib_mean": 34.6,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 167.8,
+ "cpu_pct_max_one_container": 185.9,
+ "mem_mib_mean": 554.5,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 9.0,
+ "cpu_pct_max_one_container": 10.4,
+ "mem_mib_mean": 7.0,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 7.9,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 6.38,
+ "IO:WalSync": 0.88,
+ "Client:ClientRead": 0.38,
+ "CPU:-": 0.31
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-tx-r2.k6.json b/evidence/track1/raw/g2-tx-r2.k6.json
new file mode 100644
index 00000000..2e48b07f
--- /dev/null
+++ b/evidence/track1/raw/g2-tx-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "http_req_duration{expected_response:true}": {
+ "avg": 36.08230586814928,
+ "p(50)": 32.452392,
+ "p(95)": 73.39748900000001,
+ "p(99)": 83.973901,
+ "max": 140.865762
+ },
+ "http_req_sending": {
+ "p(99)": 0.042135,
+ "max": 20.558285,
+ "avg": 0.014212150182184182,
+ "p(50)": 0.00686,
+ "p(95)": 0.0153085
+ },
+ "iterations": {
+ "rate": 3375.976243321063,
+ "count": 106115
+ },
+ "http_reqs": {
+ "count": 106211,
+ "rate": 3379.0304177484186
+ },
+ "http_req_waiting": {
+ "max": 140.822152,
+ "avg": 36.03004961504952,
+ "p(50)": 32.402143,
+ "p(95)": 73.3547685,
+ "p(99)": 83.9419072
+ },
+ "http_req_blocked": {
+ "p(95)": 0.002822,
+ "p(99)": 0.004085799999999988,
+ "max": 45.446762,
+ "avg": 0.01144355607234625,
+ "p(50)": 0.001763
+ },
+ "data_received": {
+ "count": 173069360,
+ "rate": 5506083.4736538725
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "checks": {
+ "passes": 106115,
+ "fails": 0,
+ "value": 1
+ },
+ "iteration_duration": {
+ "p(99)": 84.05643032,
+ "max": 140.964696,
+ "avg": 36.192178165414866,
+ "p(50)": 32.569338,
+ "p(95)": 73.50605269999996
+ },
+ "http_req_duration": {
+ "avg": 36.08230586814928,
+ "p(50)": 32.452392,
+ "p(95)": 73.39748900000001,
+ "p(99)": 83.973901,
+ "max": 140.865762
+ },
+ "data_sent": {
+ "count": 29631879,
+ "rate": 942717.9903780266
+ },
+ "http_req_tls_handshaking": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0,
+ "avg": 0,
+ "p(50)": 0
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 106211,
+ "value": 0
+ },
+ "vus_max": {
+ "min": 128,
+ "max": 128,
+ "value": 128
+ },
+ "http_req_connecting": {
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 43.931012,
+ "avg": 0.008876139081639381
+ },
+ "http_req_receiving": {
+ "p(50)": 0.02866,
+ "p(95)": 0.0832395,
+ "p(99)": 0.17542109999999989,
+ "max": 37.114547,
+ "avg": 0.03804410291777666
+ }
+ },
+ "root_group": {
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "post 201": {
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 74168
+ },
+ "get 200": {
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 31947
+ }
+ },
+ "name": "",
+ "path": ""
+ }
+}
diff --git a/evidence/track1/raw/g2-tx-r3.json b/evidence/track1/raw/g2-tx-r3.json
new file mode 100644
index 00000000..fe8fbf30
--- /dev/null
+++ b/evidence/track1/raw/g2-tx-r3.json
@@ -0,0 +1,65 @@
+{
+ "label": "g2-tx-r3",
+ "config": "g2-tx",
+ "series": "growth",
+ "repeat": 3,
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "tx"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088920,
+ "instances": [
+ "051cf55461bd",
+ "67c5bab35d8d"
+ ],
+ "rps": 3418.7,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 32.45,
+ "p(95)": 85.31,
+ "p(99)": 95.89,
+ "max": 122.38
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 180.2,
+ "cpu_pct_max_one_container": 106.3,
+ "mem_mib_mean": 56.6,
+ "containers": 2
+ },
+ "lb": {
+ "cpu_pct_mean": 39.5,
+ "cpu_pct_max_one_container": 48.3,
+ "mem_mib_mean": 34.3,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 159.6,
+ "cpu_pct_max_one_container": 194.9,
+ "mem_mib_mean": 588.8,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.0,
+ "cpu_pct_max_one_container": 10.0,
+ "mem_mib_mean": 7.0,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 11.9,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 10.31,
+ "IO:WalSync": 0.69,
+ "CPU:-": 0.62,
+ "Client:ClientRead": 0.31
+ }
+ }
+}
diff --git a/evidence/track1/raw/g2-tx-r3.k6.json b/evidence/track1/raw/g2-tx-r3.k6.json
new file mode 100644
index 00000000..d76722ed
--- /dev/null
+++ b/evidence/track1/raw/g2-tx-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "checks": {
+ "passes": 107154,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 107250,
+ "value": 0
+ },
+ "http_req_connecting": {
+ "p(99)": 0,
+ "max": 24.547485,
+ "avg": 0.0051019057156177165,
+ "p(50)": 0,
+ "p(95)": 0
+ },
+ "iterations": {
+ "count": 107154,
+ "rate": 3415.6568349146833
+ },
+ "http_req_duration": {
+ "p(99)": 95.89087937,
+ "max": 122.377787,
+ "avg": 35.72409434408375,
+ "p(50)": 32.44660450000001,
+ "p(95)": 85.3141335
+ },
+ "http_req_blocked": {
+ "p(99)": 0.00397,
+ "max": 26.410512,
+ "avg": 0.008078780708624805,
+ "p(50)": 0.001614,
+ "p(95)": 0.002717
+ },
+ "data_sent": {
+ "count": 29936012,
+ "rate": 954244.7691909586
+ },
+ "data_received": {
+ "count": 174299090,
+ "rate": 5555983.706421687
+ },
+ "http_req_receiving": {
+ "avg": 0.03749199503962704,
+ "p(50)": 0.026247,
+ "p(95)": 0.08329844999999979,
+ "p(99)": 0.22018812999999968,
+ "max": 48.208966
+ },
+ "iteration_duration": {
+ "avg": 35.82955041872436,
+ "p(50)": 32.6268675,
+ "p(95)": 85.39561585,
+ "p(99)": 95.99465171,
+ "max": 122.45447
+ },
+ "http_req_waiting": {
+ "max": 122.346077,
+ "avg": 35.67654342594004,
+ "p(50)": 32.3967045,
+ "p(95)": 85.26993129999998,
+ "p(99)": 95.84924799999999
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 35.72409434408375,
+ "p(50)": 32.44660450000001,
+ "p(95)": 85.3141335,
+ "p(99)": 95.89087937,
+ "max": 122.377787
+ },
+ "http_req_sending": {
+ "avg": 0.010058923104894977,
+ "p(50)": 0.006473,
+ "p(95)": 0.011651,
+ "p(99)": 0.03887152999999999,
+ "max": 19.83647
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_reqs": {
+ "count": 107250,
+ "rate": 3418.7169451872983
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 32122,
+ "fails": 0
+ },
+ "post 201": {
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 75032
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-oneshot-r1.json b/evidence/track1/raw/g4-oneshot-r1.json
new file mode 100644
index 00000000..1d413226
--- /dev/null
+++ b/evidence/track1/raw/g4-oneshot-r1.json
@@ -0,0 +1,68 @@
+{
+ "label": "g4-oneshot-r1",
+ "config": "g4-oneshot",
+ "series": "growth",
+ "repeat": 1,
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "oneshot"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088590,
+ "instances": [
+ "3387249bff48",
+ "8ee26e424d87",
+ "9e5895892177",
+ "bcd7d5ac1823"
+ ],
+ "rps": 4241.1,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 15.82,
+ "p(95)": 80.02,
+ "p(99)": 91.87,
+ "max": 163.23
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 165.5,
+ "cpu_pct_max_one_container": 48.3,
+ "mem_mib_mean": 84.0,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 55.1,
+ "cpu_pct_max_one_container": 65.8,
+ "mem_mib_mean": 34.5,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 183.0,
+ "cpu_pct_max_one_container": 210.8,
+ "mem_mib_mean": 609.8,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 10.6,
+ "cpu_pct_max_one_container": 13.9,
+ "mem_mib_mean": 7.2,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 29.0,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 25.38,
+ "CPU:-": 2.06,
+ "IO:WalSync": 0.88,
+ "Client:ClientRead": 0.62,
+ "IO:DataFileExtend": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-oneshot-r1.k6.json b/evidence/track1/raw/g4-oneshot-r1.k6.json
new file mode 100644
index 00000000..ec02e710
--- /dev/null
+++ b/evidence/track1/raw/g4-oneshot-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "http_req_tls_handshaking": {
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0,
+ "avg": 0
+ },
+ "http_req_sending": {
+ "p(50)": 0.006953,
+ "p(95)": 0.012775399999999994,
+ "p(99)": 0.05104060000000073,
+ "max": 25.644375,
+ "avg": 0.011526950574359318
+ },
+ "data_sent": {
+ "count": 37280986,
+ "rate": 1184786.1420824039
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 28.673713407446858,
+ "p(50)": 15.818206,
+ "p(95)": 80.023911,
+ "p(99)": 91.87094072000002,
+ "max": 163.226034
+ },
+ "checks": {
+ "passes": 133357,
+ "fails": 0,
+ "value": 1
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "iteration_duration": {
+ "avg": 28.783208841216027,
+ "p(50)": 15.919197,
+ "p(95)": 80.140552,
+ "p(99)": 91.98828084,
+ "max": 163.343963
+ },
+ "http_reqs": {
+ "count": 133453,
+ "rate": 4241.123478314738
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "iterations": {
+ "count": 133357,
+ "rate": 4238.072607566848
+ },
+ "http_req_blocked": {
+ "p(50)": 0.001768,
+ "p(95)": 0.003093,
+ "p(99)": 0.005365,
+ "max": 47.495071,
+ "avg": 0.007359205090930911
+ },
+ "http_req_connecting": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 43.539374,
+ "avg": 0.004666336680329403,
+ "p(50)": 0
+ },
+ "data_received": {
+ "count": 216322853,
+ "rate": 6874719.419978028
+ },
+ "http_req_duration": {
+ "avg": 28.673713407446858,
+ "p(50)": 15.818206,
+ "p(95)": 80.023911,
+ "p(99)": 91.87094072000002,
+ "max": 163.226034
+ },
+ "http_req_receiving": {
+ "avg": 0.04414364676702662,
+ "p(50)": 0.025315,
+ "p(95)": 0.106108,
+ "p(99)": 0.4801049600000003,
+ "max": 7.206442
+ },
+ "http_req_waiting": {
+ "p(50)": 15.763957,
+ "p(95)": 79.9693994,
+ "p(99)": 91.82446268,
+ "max": 163.181001,
+ "avg": 28.61804281010528
+ },
+ "http_req_failed": {
+ "fails": 133453,
+ "passes": 0,
+ "value": 0
+ }
+ },
+ "root_group": {
+ "groups": {},
+ "checks": {
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 93557,
+ "fails": 0
+ },
+ "get 200": {
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 39800
+ }
+ },
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e"
+ }
+}
diff --git a/evidence/track1/raw/g4-oneshot-r2.json b/evidence/track1/raw/g4-oneshot-r2.json
new file mode 100644
index 00000000..4f511664
--- /dev/null
+++ b/evidence/track1/raw/g4-oneshot-r2.json
@@ -0,0 +1,69 @@
+{
+ "label": "g4-oneshot-r2",
+ "config": "g4-oneshot",
+ "series": "growth",
+ "repeat": 2,
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "oneshot"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088850,
+ "instances": [
+ "1448df7495b2",
+ "298aef5572a1",
+ "637eb26cbb2b",
+ "d7c0c480cadb"
+ ],
+ "rps": 4311.1,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 15.35,
+ "p(95)": 79.09,
+ "p(99)": 91.14,
+ "max": 172.74
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 165.2,
+ "cpu_pct_max_one_container": 49.7,
+ "mem_mib_mean": 94.7,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 54.2,
+ "cpu_pct_max_one_container": 66.1,
+ "mem_mib_mean": 34.6,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 179.6,
+ "cpu_pct_max_one_container": 211.0,
+ "mem_mib_mean": 627.0,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 11.5,
+ "cpu_pct_max_one_container": 13.7,
+ "mem_mib_mean": 7.3,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 28.9,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 23.94,
+ "CPU:-": 3.06,
+ "IO:WalSync": 0.94,
+ "Client:ClientRead": 0.75,
+ "Timeout:SpinDelay": 0.19,
+ "LWLock:BufferContent": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-oneshot-r2.k6.json b/evidence/track1/raw/g4-oneshot-r2.k6.json
new file mode 100644
index 00000000..530dccba
--- /dev/null
+++ b/evidence/track1/raw/g4-oneshot-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "vus_max": {
+ "min": 128,
+ "max": 128,
+ "value": 128
+ },
+ "http_req_duration": {
+ "p(50)": 15.347428,
+ "p(95)": 79.094416,
+ "p(99)": 91.1445145,
+ "max": 172.74133,
+ "avg": 28.23338596298804
+ },
+ "http_reqs": {
+ "count": 135551,
+ "rate": 4311.117194239712
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_waiting": {
+ "p(50)": 15.290977,
+ "p(95)": 79.04616949999999,
+ "p(99)": 91.00921600000001,
+ "max": 172.719957,
+ "avg": 28.181766027864263
+ },
+ "iteration_duration": {
+ "max": 172.804365,
+ "avg": 28.340105754641797,
+ "p(50)": 15.445615,
+ "p(95)": 79.17760699999997,
+ "p(99)": 91.22655359999989
+ },
+ "http_req_receiving": {
+ "avg": 0.04119719080641254,
+ "p(50)": 0.024654,
+ "p(95)": 0.102332,
+ "p(99)": 0.4242945,
+ "max": 18.205867
+ },
+ "vus": {
+ "min": 0,
+ "max": 128,
+ "value": 128
+ },
+ "iterations": {
+ "count": 135455,
+ "rate": 4308.063972569293
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 135551,
+ "value": 0
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 28.23338596298804,
+ "p(50)": 15.347428,
+ "p(95)": 79.094416,
+ "p(99)": 91.1445145,
+ "max": 172.74133
+ },
+ "checks": {
+ "passes": 135455,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_connecting": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 36.578252,
+ "avg": 0.00769593604621139,
+ "p(50)": 0
+ },
+ "data_sent": {
+ "count": 37841530,
+ "rate": 1203526.8691439966
+ },
+ "data_received": {
+ "count": 220894608,
+ "rate": 7025418.791920687
+ },
+ "http_req_blocked": {
+ "max": 40.516169,
+ "avg": 0.010296693008535347,
+ "p(50)": 0.001689,
+ "p(95)": 0.002927,
+ "p(99)": 0.0048590000000000005
+ },
+ "http_req_sending": {
+ "avg": 0.01042274431763693,
+ "p(50)": 0.006726,
+ "p(95)": 0.012064499999999999,
+ "p(99)": 0.045909500000000006,
+ "max": 23.496833
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 94747,
+ "fails": 0
+ },
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 40708,
+ "fails": 0
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-oneshot-r3.json b/evidence/track1/raw/g4-oneshot-r3.json
new file mode 100644
index 00000000..be63d56a
--- /dev/null
+++ b/evidence/track1/raw/g4-oneshot-r3.json
@@ -0,0 +1,67 @@
+{
+ "label": "g4-oneshot-r3",
+ "config": "g4-oneshot",
+ "series": "growth",
+ "repeat": 3,
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "oneshot"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792089108,
+ "instances": [
+ "99361bc87d50",
+ "b903e6d0c6d8",
+ "d70cdba5a006",
+ "f01ef58ab3b2"
+ ],
+ "rps": 4350.3,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 15.33,
+ "p(95)": 77.91,
+ "p(99)": 92.32,
+ "max": 175.22
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 160.9,
+ "cpu_pct_max_one_container": 46.6,
+ "mem_mib_mean": 97.6,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 53.4,
+ "cpu_pct_max_one_container": 68.1,
+ "mem_mib_mean": 34.6,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 183.8,
+ "cpu_pct_max_one_container": 212.3,
+ "mem_mib_mean": 611.5,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 11.5,
+ "cpu_pct_max_one_container": 13.6,
+ "mem_mib_mean": 7.2,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 33.8,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 31.38,
+ "CPU:-": 1.06,
+ "IO:WalSync": 0.94,
+ "Client:ClientRead": 0.38
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-oneshot-r3.k6.json b/evidence/track1/raw/g4-oneshot-r3.k6.json
new file mode 100644
index 00000000..ba11d825
--- /dev/null
+++ b/evidence/track1/raw/g4-oneshot-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "iterations": {
+ "count": 136646,
+ "rate": 4347.251283273291
+ },
+ "http_req_duration": {
+ "p(95)": 77.91281790000001,
+ "p(99)": 92.31857302999998,
+ "max": 175.222841,
+ "avg": 27.982146385624574,
+ "p(50)": 15.3287635
+ },
+ "http_req_blocked": {
+ "avg": 0.006654418240189681,
+ "p(50)": 0.001622,
+ "p(95)": 0.002894,
+ "p(99)": 0.004942589999999997,
+ "max": 57.751355
+ },
+ "data_received": {
+ "count": 223218284,
+ "rate": 7101459.036993852
+ },
+ "http_req_failed": {
+ "fails": 136742,
+ "passes": 0,
+ "value": 0
+ },
+ "http_req_sending": {
+ "max": 5.035053,
+ "avg": 0.009802613337526222,
+ "p(50)": 0.00653,
+ "p(95)": 0.01181,
+ "p(99)": 0.048948479999999746
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "http_req_connecting": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 57.694799,
+ "avg": 0.004336703470769771,
+ "p(50)": 0
+ },
+ "checks": {
+ "passes": 136646,
+ "fails": 0,
+ "value": 1
+ },
+ "http_reqs": {
+ "count": 136742,
+ "rate": 4350.305424069174
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "data_sent": {
+ "count": 38167460,
+ "rate": 1214258.2985545276
+ },
+ "iteration_duration": {
+ "max": 175.28998,
+ "avg": 28.087466976647466,
+ "p(50)": 15.418322499999999,
+ "p(95)": 78.012599,
+ "p(99)": 92.42671669999997
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_waiting": {
+ "p(50)": 15.2710605,
+ "p(95)": 77.86618634999999,
+ "p(99)": 92.25811157999999,
+ "max": 175.192609,
+ "avg": 27.928089861293714
+ },
+ "http_req_receiving": {
+ "p(50)": 0.023951,
+ "p(95)": 0.10182129999999996,
+ "p(99)": 0.4685459799999982,
+ "max": 48.514512,
+ "avg": 0.04425391099296456
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(95)": 77.91281790000001,
+ "p(99)": 92.31857302999998,
+ "max": 175.222841,
+ "avg": 27.982146385624574,
+ "p(50)": 15.3287635
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "passes": 41148,
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c"
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 95498,
+ "fails": 0
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-r1.json b/evidence/track1/raw/g4-r1.json
new file mode 100644
index 00000000..fcc5a732
--- /dev/null
+++ b/evidence/track1/raw/g4-r1.json
@@ -0,0 +1,64 @@
+{
+ "label": "g4-r1",
+ "config": "g4",
+ "series": "growth",
+ "repeat": 1,
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087742,
+ "instances": [
+ "178159b6e545",
+ "1c3f4a525204",
+ "3da526a4e707",
+ "cbe1210f4569"
+ ],
+ "rps": 3740.2,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 17.91,
+ "p(95)": 85.16,
+ "p(99)": 94.86,
+ "max": 156.11
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 200.0,
+ "cpu_pct_max_one_container": 58.0,
+ "mem_mib_mean": 86.7,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 47.7,
+ "cpu_pct_max_one_container": 56.5,
+ "mem_mib_mean": 34.2,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 188.9,
+ "cpu_pct_max_one_container": 214.9,
+ "mem_mib_mean": 502.8,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.4,
+ "cpu_pct_max_one_container": 9.9,
+ "mem_mib_mean": 7.4,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 28.7,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 26.19,
+ "IO:WalSync": 0.94,
+ "CPU:-": 0.81,
+ "Client:ClientRead": 0.75
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-r1.k6.json b/evidence/track1/raw/g4-r1.k6.json
new file mode 100644
index 00000000..64c6caa2
--- /dev/null
+++ b/evidence/track1/raw/g4-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "iterations": {
+ "count": 117408,
+ "rate": 3737.1756318926755
+ },
+ "iteration_duration": {
+ "avg": 32.6935019146483,
+ "p(50)": 18.026376,
+ "p(95)": 85.2483539,
+ "p(99)": 94.95904081999998,
+ "max": 156.188468
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "vus_max": {
+ "max": 128,
+ "value": 128,
+ "min": 128
+ },
+ "data_sent": {
+ "count": 32798575,
+ "rate": 1044000.7090726723
+ },
+ "http_req_receiving": {
+ "p(95)": 0.11419009999999995,
+ "p(99)": 0.4645571500000007,
+ "max": 9.125069,
+ "avg": 0.044015715116081065,
+ "p(50)": 0.023403
+ },
+ "http_reqs": {
+ "count": 117504,
+ "rate": 3740.231376481304
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 117504,
+ "value": 0
+ },
+ "http_req_waiting": {
+ "avg": 32.526591769701476,
+ "p(50)": 17.855754500000003,
+ "p(95)": 85.10775274999999,
+ "p(99)": 94.81392489000001,
+ "max": 156.082623
+ },
+ "http_req_blocked": {
+ "p(50)": 0.001615,
+ "p(95)": 0.002847,
+ "p(99)": 0.004966910000000003,
+ "max": 26.377727,
+ "avg": 0.008365860583469496
+ },
+ "http_req_duration": {
+ "avg": 32.581837125025366,
+ "p(50)": 17.910674999999998,
+ "p(95)": 85.15560909999999,
+ "p(99)": 94.86120549,
+ "max": 156.110465
+ },
+ "checks": {
+ "passes": 117408,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 32.581837125025366,
+ "p(50)": 17.910674999999998,
+ "p(95)": 85.15560909999999,
+ "p(99)": 94.86120549,
+ "max": 156.110465
+ },
+ "http_req_sending": {
+ "max": 23.918443,
+ "avg": 0.011229640207992874,
+ "p(50)": 0.006554,
+ "p(95)": 0.011861849999999991,
+ "p(99)": 0.05429131000000003
+ },
+ "http_req_connecting": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 26.217462,
+ "avg": 0.006226310695806102,
+ "p(50)": 0
+ },
+ "data_received": {
+ "count": 191005558,
+ "rate": 6079835.419338231
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "post 201": {
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 82195,
+ "fails": 0,
+ "name": "post 201"
+ },
+ "get 200": {
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 35213,
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200"
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-r2.json b/evidence/track1/raw/g4-r2.json
new file mode 100644
index 00000000..4d7820e6
--- /dev/null
+++ b/evidence/track1/raw/g4-r2.json
@@ -0,0 +1,64 @@
+{
+ "label": "g4-r2",
+ "config": "g4",
+ "series": "growth",
+ "repeat": 2,
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087974,
+ "instances": [
+ "27bc3ddd90d7",
+ "c1a336718690",
+ "c84b09aaa2b6",
+ "fc21c32d1d67"
+ ],
+ "rps": 3558.6,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 17.92,
+ "p(95)": 87.61,
+ "p(99)": 97.52,
+ "max": 161.08
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 198.3,
+ "cpu_pct_max_one_container": 55.5,
+ "mem_mib_mean": 89.8,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 45.3,
+ "cpu_pct_max_one_container": 52.7,
+ "mem_mib_mean": 34.3,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 182.9,
+ "cpu_pct_max_one_container": 212.4,
+ "mem_mib_mean": 599.2,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 9.9,
+ "cpu_pct_max_one_container": 11.2,
+ "mem_mib_mean": 7.3,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 27.9,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 23.19,
+ "CPU:-": 2.44,
+ "Client:ClientRead": 1.38,
+ "IO:WalSync": 0.94
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-r2.k6.json b/evidence/track1/raw/g4-r2.k6.json
new file mode 100644
index 00000000..dffc5316
--- /dev/null
+++ b/evidence/track1/raw/g4-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 33492,
+ "fails": 0
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 78371,
+ "fails": 0
+ }
+ },
+ "name": "",
+ "path": ""
+ },
+ "metrics": {
+ "http_reqs": {
+ "count": 111959,
+ "rate": 3558.615067286883
+ },
+ "checks": {
+ "passes": 111863,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_duration": {
+ "max": 161.080613,
+ "avg": 34.22779857078918,
+ "p(50)": 17.922269,
+ "p(95)": 87.61406119999998,
+ "p(99)": 97.51781754
+ },
+ "vus_max": {
+ "max": 128,
+ "value": 128,
+ "min": 128
+ },
+ "iterations": {
+ "count": 111863,
+ "rate": 3555.563708785471
+ },
+ "iteration_duration": {
+ "avg": 34.36355381666867,
+ "p(50)": 18.031527,
+ "p(95)": 87.73417769999998,
+ "p(99)": 97.64292894,
+ "max": 161.415287
+ },
+ "http_req_blocked": {
+ "p(99)": 0.005346099999999991,
+ "max": 33.284427,
+ "avg": 0.01022608342339587,
+ "p(50)": 0.001792,
+ "p(95)": 0.003018
+ },
+ "http_req_sending": {
+ "avg": 0.010687094874016327,
+ "p(50)": 0.007023,
+ "p(95)": 0.012537,
+ "p(99)": 0.05262193999999981,
+ "max": 4.390358
+ },
+ "http_req_receiving": {
+ "avg": 0.047793689296974785,
+ "p(50)": 0.025329,
+ "p(95)": 0.11854329999999928,
+ "p(99)": 0.4572271599999992,
+ "max": 33.568975
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(99)": 97.51781754,
+ "max": 161.080613,
+ "avg": 34.22779857078918,
+ "p(50)": 17.922269,
+ "p(95)": 87.61406119999998
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "data_sent": {
+ "count": 31255792,
+ "rate": 993464.8608078387
+ },
+ "http_req_waiting": {
+ "p(50)": 17.859966,
+ "p(95)": 87.54871279999998,
+ "p(99)": 97.4834917,
+ "max": 161.06362,
+ "avg": 34.16931778661809
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 111959,
+ "value": 0
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "data_received": {
+ "rate": 5775584.258880182,
+ "count": 181707947
+ },
+ "http_req_connecting": {
+ "max": 32.948568,
+ "avg": 0.007591478871729832,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-r3.json b/evidence/track1/raw/g4-r3.json
new file mode 100644
index 00000000..a5ce5b1b
--- /dev/null
+++ b/evidence/track1/raw/g4-r3.json
@@ -0,0 +1,67 @@
+{
+ "label": "g4-r3",
+ "config": "g4",
+ "series": "growth",
+ "repeat": 3,
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088209,
+ "instances": [
+ "1ba14979fb6f",
+ "3555ff0c37a3",
+ "3d271507a427",
+ "a6f38d1b0641"
+ ],
+ "rps": 3635.9,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 19.7,
+ "p(95)": 84.54,
+ "p(99)": 94.54,
+ "max": 113.77
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 197.0,
+ "cpu_pct_max_one_container": 56.6,
+ "mem_mib_mean": 96.2,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 47.1,
+ "cpu_pct_max_one_container": 53.8,
+ "mem_mib_mean": 34.6,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 189.9,
+ "cpu_pct_max_one_container": 210.2,
+ "mem_mib_mean": 650.0,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 9.0,
+ "cpu_pct_max_one_container": 11.4,
+ "mem_mib_mean": 7.3,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 28.5,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 23.75,
+ "CPU:-": 2.5,
+ "Client:ClientRead": 1.19,
+ "IO:WalSync": 0.88,
+ "LWLock:XidGenLock": 0.06,
+ "LWLock:WALInsert": 0.06,
+ "LWLock:BufferContent": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-r3.k6.json b/evidence/track1/raw/g4-r3.k6.json
new file mode 100644
index 00000000..60b6933e
--- /dev/null
+++ b/evidence/track1/raw/g4-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "root_group": {
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "passes": 34163,
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c"
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 79969,
+ "fails": 0
+ }
+ },
+ "name": ""
+ },
+ "metrics": {
+ "http_req_sending": {
+ "avg": 0.012107030010155484,
+ "p(50)": 0.006554,
+ "p(95)": 0.011564649999999994,
+ "p(99)": 0.04668091999999999,
+ "max": 34.119122
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 114228,
+ "value": 0
+ },
+ "http_req_connecting": {
+ "avg": 0.013015724507126097,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 34.539539
+ },
+ "http_req_tls_handshaking": {
+ "max": 0,
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(50)": 19.696336000000002,
+ "p(95)": 84.5435124,
+ "p(99)": 94.53683215000001,
+ "max": 113.772923,
+ "avg": 33.51075426137192
+ },
+ "http_req_duration": {
+ "avg": 33.51075426137192,
+ "p(50)": 19.696336000000002,
+ "p(95)": 84.5435124,
+ "p(99)": 94.53683215000001,
+ "max": 113.772923
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "http_req_blocked": {
+ "avg": 0.019743180078439376,
+ "p(50)": 0.001653,
+ "p(95)": 0.002874,
+ "p(99)": 0.005072329999999914,
+ "max": 40.081657
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "http_reqs": {
+ "count": 114228,
+ "rate": 3635.9319713140444
+ },
+ "data_sent": {
+ "count": 31890673,
+ "rate": 1015095.4017178062
+ },
+ "iteration_duration": {
+ "avg": 33.632467191462325,
+ "p(50)": 19.825204499999998,
+ "p(95)": 84.64612404999998,
+ "p(99)": 94.65069106000003,
+ "max": 113.835114
+ },
+ "http_req_receiving": {
+ "avg": 0.04369142117519393,
+ "p(50)": 0.024173,
+ "p(95)": 0.10984599999999989,
+ "p(99)": 0.4397129499999967,
+ "max": 6.305495
+ },
+ "http_req_waiting": {
+ "avg": 33.45495581018663,
+ "p(50)": 19.6366665,
+ "p(95)": 84.50681124999998,
+ "p(99)": 94.50618852999999,
+ "max": 113.750683
+ },
+ "checks": {
+ "passes": 114132,
+ "fails": 0,
+ "value": 1
+ },
+ "data_received": {
+ "count": 185364209,
+ "rate": 5900231.588055805
+ },
+ "iterations": {
+ "count": 114132,
+ "rate": 3632.876245316512
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-tx-k6cpu8-r1.json b/evidence/track1/raw/g4-tx-k6cpu8-r1.json
new file mode 100644
index 00000000..61e54ecf
--- /dev/null
+++ b/evidence/track1/raw/g4-tx-k6cpu8-r1.json
@@ -0,0 +1,67 @@
+{
+ "label": "g4-tx-k6cpu8-r1",
+ "config": "g4-tx-k6cpu8",
+ "series": "growth",
+ "repeat": 1,
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "tx"
+ },
+ "k6_cpus": "8",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792089181,
+ "instances": [
+ "64b7520c8669",
+ "c7060ae9b40c",
+ "dbc556069a4e",
+ "e6d73feec604"
+ ],
+ "rps": 3516.0,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 18.85,
+ "p(95)": 85.86,
+ "p(99)": 95.84,
+ "max": 165.0
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 196.7,
+ "cpu_pct_max_one_container": 56.5,
+ "mem_mib_mean": 89.8,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 48.0,
+ "cpu_pct_max_one_container": 59.8,
+ "mem_mib_mean": 34.5,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 186.8,
+ "cpu_pct_max_one_container": 212.0,
+ "mem_mib_mean": 598.5,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.3,
+ "cpu_pct_max_one_container": 9.6,
+ "mem_mib_mean": 6.9,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 27.1,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 23.19,
+ "CPU:-": 1.5,
+ "Client:ClientRead": 1.5,
+ "IO:WalSync": 0.94
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-tx-k6cpu8-r1.k6.json b/evidence/track1/raw/g4-tx-k6cpu8-r1.k6.json
new file mode 100644
index 00000000..5356f64e
--- /dev/null
+++ b/evidence/track1/raw/g4-tx-k6cpu8-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "http_req_sending": {
+ "avg": 0.011752126366972265,
+ "p(50)": 0.006949,
+ "p(95)": 0.01273975,
+ "p(99)": 0.054965000000000236,
+ "max": 23.523265
+ },
+ "checks": {
+ "passes": 110550,
+ "fails": 0,
+ "value": 1
+ },
+ "http_reqs": {
+ "count": 110646,
+ "rate": 3515.9630089754946
+ },
+ "http_req_blocked": {
+ "max": 36.225465,
+ "avg": 0.013141761708511775,
+ "p(50)": 0.001738,
+ "p(95)": 0.003018,
+ "p(99)": 0.0057466500000000085
+ },
+ "http_req_connecting": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 34.868982,
+ "avg": 0.010439337490736224,
+ "p(50)": 0
+ },
+ "http_req_tls_handshaking": {
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0,
+ "avg": 0,
+ "p(50)": 0
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(99)": 95.84202045000004,
+ "max": 164.997176,
+ "avg": 34.61088926596521,
+ "p(50)": 18.851928,
+ "p(95)": 85.85737425
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "data_received": {
+ "count": 180178789,
+ "rate": 5725484.492218433
+ },
+ "vus": {
+ "min": 0,
+ "max": 128,
+ "value": 128
+ },
+ "iteration_duration": {
+ "avg": 34.73569572593428,
+ "p(50)": 18.977851,
+ "p(95)": 85.97769815,
+ "p(99)": 96.00669203,
+ "max": 165.123395
+ },
+ "http_req_duration": {
+ "avg": 34.61088926596521,
+ "p(50)": 18.851928,
+ "p(95)": 85.85737425,
+ "p(99)": 95.84202045000004,
+ "max": 164.997176
+ },
+ "http_req_receiving": {
+ "avg": 0.0469211477685596,
+ "p(50)": 0.025152,
+ "p(95)": 0.12086575,
+ "p(99)": 0.4995463000000003,
+ "max": 6.400129
+ },
+ "http_req_waiting": {
+ "avg": 34.55221599182961,
+ "p(50)": 18.7936775,
+ "p(95)": 85.81172325,
+ "p(99)": 95.79274070000001,
+ "max": 164.88251
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 110646,
+ "value": 0
+ },
+ "data_sent": {
+ "count": 30875816,
+ "rate": 981131.0569558205
+ },
+ "iterations": {
+ "count": 110550,
+ "rate": 3512.912447284501
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 33228,
+ "fails": 0
+ },
+ "post 201": {
+ "passes": 77322,
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9"
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-tx-r1.json b/evidence/track1/raw/g4-tx-r1.json
new file mode 100644
index 00000000..7ebf5be6
--- /dev/null
+++ b/evidence/track1/raw/g4-tx-r1.json
@@ -0,0 +1,68 @@
+{
+ "label": "g4-tx-r1",
+ "config": "g4-tx",
+ "series": "growth",
+ "repeat": 1,
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "tx"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088463,
+ "instances": [
+ "2d3e8f200676",
+ "472df8f3db20",
+ "650801e7809c",
+ "bddd7010c084"
+ ],
+ "rps": 3600.0,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 18.57,
+ "p(95)": 84.59,
+ "p(99)": 94.52,
+ "max": 158.36
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 194.1,
+ "cpu_pct_max_one_container": 56.1,
+ "mem_mib_mean": 88.9,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 47.4,
+ "cpu_pct_max_one_container": 56.0,
+ "mem_mib_mean": 34.4,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 187.7,
+ "cpu_pct_max_one_container": 214.9,
+ "mem_mib_mean": 631.4,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.4,
+ "cpu_pct_max_one_container": 10.2,
+ "mem_mib_mean": 7.2,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 28.6,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 23.75,
+ "CPU:-": 2.06,
+ "Client:ClientRead": 1.62,
+ "IO:WalSync": 0.94,
+ "LWLock:LockManager": 0.19
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-tx-r1.k6.json b/evidence/track1/raw/g4-tx-r1.k6.json
new file mode 100644
index 00000000..95489b54
--- /dev/null
+++ b/evidence/track1/raw/g4-tx-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "http_req_waiting": {
+ "avg": 33.80154199459966,
+ "p(50)": 18.520197,
+ "p(95)": 84.55157859999998,
+ "p(99)": 94.48547335999999,
+ "max": 158.334181
+ },
+ "http_req_receiving": {
+ "avg": 0.04353121877237115,
+ "p(50)": 0.024086,
+ "p(95)": 0.11093779999999999,
+ "p(99)": 0.45912151999999984,
+ "max": 21.547512
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 113145,
+ "value": 0
+ },
+ "http_req_connecting": {
+ "max": 36.411069,
+ "avg": 0.00875542282027487,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0
+ },
+ "http_req_duration": {
+ "p(95)": 84.5890474,
+ "p(99)": 94.52009099999998,
+ "max": 158.357126,
+ "avg": 33.85633336227863,
+ "p(50)": 18.573522
+ },
+ "http_req_blocked": {
+ "p(50)": 0.001657,
+ "p(95)": 0.002892,
+ "p(99)": 0.005023799999999989,
+ "max": 39.209163,
+ "avg": 0.012256723708515525
+ },
+ "http_req_sending": {
+ "p(95)": 0.011750799999999988,
+ "p(99)": 0.051575679999999936,
+ "max": 25.006553,
+ "avg": 0.011260148906270894,
+ "p(50)": 0.006629
+ },
+ "checks": {
+ "passes": 113049,
+ "fails": 0,
+ "value": 1
+ },
+ "data_sent": {
+ "count": 31583057,
+ "rate": 1004889.6001285727
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(95)": 84.5890474,
+ "p(99)": 94.52009099999998,
+ "max": 158.357126,
+ "avg": 33.85633336227863,
+ "p(50)": 18.573522
+ },
+ "iteration_duration": {
+ "p(50)": 18.683681,
+ "p(95)": 84.69243299999998,
+ "p(99)": 94.66317540000003,
+ "max": 158.424961,
+ "avg": 33.97518160023535
+ },
+ "iterations": {
+ "count": 113049,
+ "rate": 3596.92110883804
+ },
+ "vus_max": {
+ "max": 128,
+ "value": 128,
+ "min": 128
+ },
+ "http_reqs": {
+ "count": 113145,
+ "rate": 3599.9755757192015
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "vus": {
+ "min": 0,
+ "max": 128,
+ "value": 128
+ },
+ "data_received": {
+ "count": 183892641,
+ "rate": 5850978.97524857
+ }
+ },
+ "root_group": {
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 33887,
+ "fails": 0
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 79162,
+ "fails": 0
+ }
+ },
+ "name": ""
+ }
+}
diff --git a/evidence/track1/raw/g4-tx-r2.json b/evidence/track1/raw/g4-tx-r2.json
new file mode 100644
index 00000000..c7b1051c
--- /dev/null
+++ b/evidence/track1/raw/g4-tx-r2.json
@@ -0,0 +1,68 @@
+{
+ "label": "g4-tx-r2",
+ "config": "g4-tx",
+ "series": "growth",
+ "repeat": 2,
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "tx"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088721,
+ "instances": [
+ "6794a328b231",
+ "859772e8a53b",
+ "c29c8bf434b0",
+ "cf7e64036c19"
+ ],
+ "rps": 3248.5,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 19.87,
+ "p(95)": 88.84,
+ "p(99)": 96.6,
+ "max": 343.56
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 195.0,
+ "cpu_pct_max_one_container": 57.1,
+ "mem_mib_mean": 88.8,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 46.6,
+ "cpu_pct_max_one_container": 54.3,
+ "mem_mib_mean": 34.4,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 187.9,
+ "cpu_pct_max_one_container": 211.6,
+ "mem_mib_mean": 593.2,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.1,
+ "cpu_pct_max_one_container": 9.3,
+ "mem_mib_mean": 6.9,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 31.7,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 27.25,
+ "CPU:-": 2.0,
+ "Client:ClientRead": 1.5,
+ "IO:WalSync": 0.88,
+ "IPC:ProcarrayGroupUpdate": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-tx-r2.k6.json b/evidence/track1/raw/g4-tx-r2.k6.json
new file mode 100644
index 00000000..abb21ef9
--- /dev/null
+++ b/evidence/track1/raw/g4-tx-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "http_reqs": {
+ "count": 102247,
+ "rate": 3248.483905489285
+ },
+ "http_req_sending": {
+ "p(50)": 0.007302,
+ "p(95)": 0.014651699999999997,
+ "p(99)": 0.06771615999999774,
+ "max": 30.779418,
+ "avg": 0.018326491320039082
+ },
+ "http_req_waiting": {
+ "p(95)": 88.7858619,
+ "p(99)": 96.52987116,
+ "max": 343.52195,
+ "avg": 37.37677830906566,
+ "p(50)": 19.802978
+ },
+ "data_received": {
+ "count": 166408896,
+ "rate": 5286968.032179333
+ },
+ "http_req_blocked": {
+ "max": 77.908761,
+ "avg": 0.016825385566324354,
+ "p(50)": 0.001867,
+ "p(95)": 0.003242,
+ "p(99)": 0.0062740799999999874
+ },
+ "iterations": {
+ "count": 102151,
+ "rate": 3245.433894682836
+ },
+ "data_sent": {
+ "count": 28529892,
+ "rate": 906421.6552793481
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 37.451888343843244,
+ "p(50)": 19.874462,
+ "p(95)": 88.8421811,
+ "p(99)": 96.60133945999999,
+ "max": 343.564868
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "checks": {
+ "passes": 102151,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 102247,
+ "value": 0
+ },
+ "http_req_receiving": {
+ "avg": 0.05678354345848797,
+ "p(50)": 0.026236,
+ "p(95)": 0.13789299999999985,
+ "p(99)": 0.6162322799999985,
+ "max": 28.284715
+ },
+ "iteration_duration": {
+ "avg": 37.599757805542524,
+ "p(50)": 20.033745,
+ "p(95)": 88.939544,
+ "p(99)": 96.733491,
+ "max": 343.726313
+ },
+ "http_req_connecting": {
+ "avg": 0.009429554001584402,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 47.934722
+ },
+ "http_req_duration": {
+ "avg": 37.451888343843244,
+ "p(50)": 19.874462,
+ "p(95)": 88.8421811,
+ "p(99)": 96.60133945999999,
+ "max": 343.564868
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 30706,
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200"
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 71445,
+ "fails": 0
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-tx-r3.json b/evidence/track1/raw/g4-tx-r3.json
new file mode 100644
index 00000000..8a2eafbd
--- /dev/null
+++ b/evidence/track1/raw/g4-tx-r3.json
@@ -0,0 +1,69 @@
+{
+ "label": "g4-tx-r3",
+ "config": "g4-tx",
+ "series": "growth",
+ "repeat": 3,
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "tx"
+ },
+ "k6_cpus": "4",
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088978,
+ "instances": [
+ "3bac93987e05",
+ "9b2aed4dbea8",
+ "a286be030052",
+ "dd010d973129"
+ ],
+ "rps": 3572.8,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 17.44,
+ "p(95)": 89.47,
+ "p(99)": 99.54,
+ "max": 173.17
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 196.3,
+ "cpu_pct_max_one_container": 58.0,
+ "mem_mib_mean": 93.8,
+ "containers": 4
+ },
+ "lb": {
+ "cpu_pct_mean": 47.4,
+ "cpu_pct_max_one_container": 55.6,
+ "mem_mib_mean": 34.4,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 187.6,
+ "cpu_pct_max_one_container": 215.5,
+ "mem_mib_mean": 622.0,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.4,
+ "cpu_pct_max_one_container": 9.7,
+ "mem_mib_mean": 7.2,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 16,
+ "active_backends_mean": 30.5,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 27.38,
+ "CPU:-": 1.12,
+ "Client:ClientRead": 1.0,
+ "IO:WalSync": 0.88,
+ "LWLock:XidGenLock": 0.06,
+ "IO:WalWrite": 0.06
+ }
+ }
+}
diff --git a/evidence/track1/raw/g4-tx-r3.k6.json b/evidence/track1/raw/g4-tx-r3.k6.json
new file mode 100644
index 00000000..61d124f6
--- /dev/null
+++ b/evidence/track1/raw/g4-tx-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "http_req_waiting": {
+ "max": 173.125044,
+ "avg": 34.0018892013692,
+ "p(50)": 17.3722915,
+ "p(95)": 89.43454794999998,
+ "p(99)": 99.49590264999996
+ },
+ "http_req_duration": {
+ "p(99)": 99.54411184,
+ "max": 173.171913,
+ "avg": 34.060412211240475,
+ "p(50)": 17.438571,
+ "p(95)": 89.47149844999994
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(50)": 17.438571,
+ "p(95)": 89.47149844999994,
+ "p(99)": 99.54411184,
+ "max": 173.171913,
+ "avg": 34.060412211240475
+ },
+ "checks": {
+ "passes": 112354,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_receiving": {
+ "avg": 0.046721758728323175,
+ "p(50)": 0.024624,
+ "p(95)": 0.11765324999999958,
+ "p(99)": 0.49517392999999926,
+ "max": 7.61315
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 112450,
+ "value": 0
+ },
+ "iterations": {
+ "count": 112354,
+ "rate": 3569.7985872311533
+ },
+ "iteration_duration": {
+ "p(95)": 89.60453954999998,
+ "p(99)": 99.65503677,
+ "max": 173.253675,
+ "avg": 34.18094605930348,
+ "p(50)": 17.539774
+ },
+ "data_sent": {
+ "count": 31369603,
+ "rate": 996699.4007458759
+ },
+ "data_received": {
+ "count": 183551183,
+ "rate": 5831930.805828069
+ },
+ "http_req_blocked": {
+ "avg": 0.011703412307692292,
+ "p(50)": 0.00169,
+ "p(95)": 0.002963,
+ "p(99)": 0.005144509999999995,
+ "max": 44.090956
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "http_reqs": {
+ "count": 112450,
+ "rate": 3572.848773823301
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_sending": {
+ "p(95)": 0.012305549999999988,
+ "p(99)": 0.051981879999999536,
+ "max": 41.261689,
+ "avg": 0.011801251142730142,
+ "p(50)": 0.006787
+ },
+ "http_req_connecting": {
+ "avg": 0.007257102196531795,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 42.43279
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 33863,
+ "fails": 0,
+ "name": "get 200",
+ "path": "::get 200"
+ },
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 78491,
+ "fails": 0
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/g8-r1.json b/evidence/track1/raw/g8-r1.json
new file mode 100644
index 00000000..ba52f498
--- /dev/null
+++ b/evidence/track1/raw/g8-r1.json
@@ -0,0 +1,70 @@
+{
+ "label": "g8-r1",
+ "config": "g8",
+ "series": "growth",
+ "repeat": 1,
+ "replicas": 8,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792087801,
+ "instances": [
+ "106d4c65f9f4",
+ "1966eaad3f82",
+ "6982adaa6313",
+ "6b6fd606029c",
+ "74c1a629efb1",
+ "758709413ed1",
+ "dc95feda3da1",
+ "eb6452d1a62d"
+ ],
+ "rps": 3333.7,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 13.69,
+ "p(95)": 89.44,
+ "p(99)": 98.84,
+ "max": 907.22
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 187.5,
+ "cpu_pct_max_one_container": 28.2,
+ "mem_mib_mean": 178.4,
+ "containers": 8
+ },
+ "lb": {
+ "cpu_pct_mean": 47.9,
+ "cpu_pct_max_one_container": 60.9,
+ "mem_mib_mean": 34.2,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 183.6,
+ "cpu_pct_max_one_container": 212.3,
+ "mem_mib_mean": 634.8,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.3,
+ "cpu_pct_max_one_container": 10.5,
+ "mem_mib_mean": 8.0,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 15,
+ "active_backends_mean": 51.2,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 41.67,
+ "CPU:-": 4.73,
+ "Client:ClientRead": 3.53,
+ "IO:WalSync": 0.87,
+ "LWLock:XidGenLock": 0.2,
+ "LWLock:BufferContent": 0.2
+ }
+ }
+}
diff --git a/evidence/track1/raw/g8-r1.k6.json b/evidence/track1/raw/g8-r1.k6.json
new file mode 100644
index 00000000..e557f9d7
--- /dev/null
+++ b/evidence/track1/raw/g8-r1.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "vus": {
+ "min": 0,
+ "max": 128,
+ "value": 128
+ },
+ "http_req_duration": {
+ "avg": 36.314859508679845,
+ "p(50)": 13.688023000000001,
+ "p(95)": 89.43878765,
+ "p(99)": 98.83715658999999,
+ "max": 907.219503
+ },
+ "http_req_receiving": {
+ "avg": 0.07975864039880978,
+ "p(50)": 0.022925,
+ "p(95)": 0.19327509999999976,
+ "p(99)": 1.6107870099999897,
+ "max": 199.526219
+ },
+ "vus_max": {
+ "min": 128,
+ "max": 128,
+ "value": 128
+ },
+ "http_req_blocked": {
+ "avg": 0.03147124431289995,
+ "p(50)": 0.0017304999999999998,
+ "p(95)": 0.003141,
+ "p(99)": 0.01046661999999988,
+ "max": 73.811445
+ },
+ "iteration_duration": {
+ "p(50)": 13.8084435,
+ "p(95)": 89.56952439999999,
+ "p(99)": 98.97127105000001,
+ "max": 907.304495,
+ "avg": 36.482955774796494
+ },
+ "data_received": {
+ "count": 171516611,
+ "rate": 5424137.138219554
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 105414,
+ "value": 0
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "http_req_sending": {
+ "avg": 0.021068563976321862,
+ "p(50)": 0.006964,
+ "p(95)": 0.014638699999999982,
+ "p(99)": 0.13872288999999885,
+ "max": 39.675335
+ },
+ "data_sent": {
+ "count": 29415493,
+ "rate": 930251.9860326375
+ },
+ "http_req_duration{expected_response:true}": {
+ "avg": 36.314859508679845,
+ "p(50)": 13.688023000000001,
+ "p(95)": 89.43878765,
+ "p(99)": 98.83715658999999,
+ "max": 907.219503
+ },
+ "iterations": {
+ "count": 105318,
+ "rate": 3330.635276620566
+ },
+ "http_reqs": {
+ "count": 105414,
+ "rate": 3333.6712342589144
+ },
+ "http_req_connecting": {
+ "avg": 0.027141053636139417,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 73.789427
+ },
+ "http_req_waiting": {
+ "p(50)": 13.5801545,
+ "p(95)": 89.34135414999999,
+ "p(99)": 98.77245370999994,
+ "max": 907.178971,
+ "avg": 36.21403230430484
+ },
+ "checks": {
+ "passes": 105318,
+ "fails": 0,
+ "value": 1
+ }
+ },
+ "root_group": {
+ "groups": {},
+ "checks": {
+ "post 201": {
+ "name": "post 201",
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 73671,
+ "fails": 0
+ },
+ "get 200": {
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 31647,
+ "fails": 0,
+ "name": "get 200"
+ }
+ },
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e"
+ }
+}
diff --git a/evidence/track1/raw/g8-r2.json b/evidence/track1/raw/g8-r2.json
new file mode 100644
index 00000000..460f8e5e
--- /dev/null
+++ b/evidence/track1/raw/g8-r2.json
@@ -0,0 +1,70 @@
+{
+ "label": "g8-r2",
+ "config": "g8",
+ "series": "growth",
+ "repeat": 2,
+ "replicas": 8,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088034,
+ "instances": [
+ "1dadd26887ed",
+ "4a6f73456614",
+ "80349950e237",
+ "9844cfc9baad",
+ "bf090505d768",
+ "c88beecdf2f1",
+ "cd51537dfbb6",
+ "fb7056dcc66a"
+ ],
+ "rps": 3396.1,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 14.28,
+ "p(95)": 89.13,
+ "p(99)": 95.91,
+ "max": 295.27
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 182.1,
+ "cpu_pct_max_one_container": 28.9,
+ "mem_mib_mean": 167.1,
+ "containers": 8
+ },
+ "lb": {
+ "cpu_pct_mean": 48.0,
+ "cpu_pct_max_one_container": 76.4,
+ "mem_mib_mean": 34.3,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 177.6,
+ "cpu_pct_max_one_container": 206.7,
+ "mem_mib_mean": 699.9,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 7.4,
+ "cpu_pct_max_one_container": 9.6,
+ "mem_mib_mean": 8.0,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 15,
+ "active_backends_mean": 45.6,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 37.07,
+ "LWLock:BufferContent": 3.33,
+ "Client:ClientRead": 2.2,
+ "CPU:-": 2.0,
+ "IO:WalSync": 0.93,
+ "LWLock:WALInsert": 0.07
+ }
+ }
+}
diff --git a/evidence/track1/raw/g8-r2.k6.json b/evidence/track1/raw/g8-r2.k6.json
new file mode 100644
index 00000000..540ff4e1
--- /dev/null
+++ b/evidence/track1/raw/g8-r2.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "http_req_receiving": {
+ "avg": 0.09830298346431156,
+ "p(50)": 0.024039,
+ "p(95)": 0.22162139999999864,
+ "p(99)": 1.987686679999986,
+ "max": 40.105616
+ },
+ "http_reqs": {
+ "rate": 3396.0689332132174,
+ "count": 107525
+ },
+ "http_req_sending": {
+ "p(99)": 0.15724907999999876,
+ "max": 44.176686,
+ "avg": 0.022642536777493633,
+ "p(50)": 0.007226,
+ "p(95)": 0.015408399999999966
+ },
+ "checks": {
+ "fails": 0,
+ "passes": 107429,
+ "value": 1
+ },
+ "http_req_tls_handshaking": {
+ "max": 0,
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(50)": 14.27862,
+ "p(95)": 89.1273004,
+ "p(99)": 95.90637231999999,
+ "max": 295.266731,
+ "avg": 35.61848844774689
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 107525,
+ "value": 0
+ },
+ "iterations": {
+ "count": 107429,
+ "rate": 3393.0368698085354
+ },
+ "vus_max": {
+ "value": 128,
+ "min": 128,
+ "max": 128
+ },
+ "http_req_blocked": {
+ "max": 79.491267,
+ "avg": 0.020952409514067464,
+ "p(50)": 0.001834,
+ "p(95)": 0.003253,
+ "p(99)": 0.010338039999999979
+ },
+ "http_req_connecting": {
+ "avg": 0.011860117414554753,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 48.032538
+ },
+ "data_sent": {
+ "count": 30044459,
+ "rate": 948924.0067435318
+ },
+ "iteration_duration": {
+ "max": 295.313445,
+ "avg": 35.78597891197896,
+ "p(50)": 14.409316,
+ "p(95)": 89.2889474,
+ "p(99)": 96.07171196
+ },
+ "http_req_waiting": {
+ "p(95)": 89.0070746,
+ "p(99)": 95.80844135999999,
+ "max": 295.251633,
+ "avg": 35.4975429275049,
+ "p(50)": 14.131133
+ },
+ "http_req_duration": {
+ "avg": 35.61848844774689,
+ "p(50)": 14.27862,
+ "p(95)": 89.1273004,
+ "p(99)": 95.90637231999999,
+ "max": 295.266731
+ },
+ "data_received": {
+ "count": 173389500,
+ "rate": 5476332.8927725945
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 31897,
+ "fails": 0
+ },
+ "post 201": {
+ "path": "::post 201",
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 75532,
+ "fails": 0,
+ "name": "post 201"
+ }
+ }
+ }
+}
diff --git a/evidence/track1/raw/g8-r3.json b/evidence/track1/raw/g8-r3.json
new file mode 100644
index 00000000..8a29e3b7
--- /dev/null
+++ b/evidence/track1/raw/g8-r3.json
@@ -0,0 +1,68 @@
+{
+ "label": "g8-r3",
+ "config": "g8",
+ "series": "growth",
+ "repeat": 3,
+ "replicas": 8,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "vus": 128,
+ "duration": "30s",
+ "started_unix": 1792088268,
+ "instances": [
+ "0a251de3a3e3",
+ "42305d2e6f8f",
+ "59728a6359fe",
+ "68d608834503",
+ "7b7d5a37c5f6",
+ "c2df70a9467a",
+ "c5284abee82f",
+ "d4ad81711b62"
+ ],
+ "rps": 3494.0,
+ "error_ratio": 0,
+ "latency_ms": {
+ "p(50)": 14.34,
+ "p(95)": 88.76,
+ "p(99)": 95.43,
+ "max": 173.14
+ },
+ "docker_stats": {
+ "api": {
+ "cpu_pct_mean": 186.3,
+ "cpu_pct_max_one_container": 28.6,
+ "mem_mib_mean": 180.7,
+ "containers": 8
+ },
+ "lb": {
+ "cpu_pct_mean": 45.5,
+ "cpu_pct_max_one_container": 57.3,
+ "mem_mib_mean": 34.4,
+ "containers": 1
+ },
+ "postgres": {
+ "cpu_pct_mean": 179.9,
+ "cpu_pct_max_one_container": 213.5,
+ "mem_mib_mean": 692.6,
+ "containers": 1
+ },
+ "valkey": {
+ "cpu_pct_mean": 8.5,
+ "cpu_pct_max_one_container": 11.1,
+ "mem_mib_mean": 7.7,
+ "containers": 1
+ }
+ },
+ "postgres": {
+ "samples": 15,
+ "active_backends_mean": 48.0,
+ "wait_events_mean": {
+ "LWLock:WALWriteLock": 42.33,
+ "CPU:-": 2.4,
+ "Client:ClientRead": 2.4,
+ "IO:WalSync": 0.87
+ }
+ }
+}
diff --git a/evidence/track1/raw/g8-r3.k6.json b/evidence/track1/raw/g8-r3.k6.json
new file mode 100644
index 00000000..dbe905d9
--- /dev/null
+++ b/evidence/track1/raw/g8-r3.k6.json
@@ -0,0 +1,125 @@
+{
+ "metrics": {
+ "http_req_connecting": {
+ "avg": 0.005628038389538509,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 23.365782
+ },
+ "http_req_duration{expected_response:true}": {
+ "p(99)": 95.42866276000001,
+ "max": 173.13552,
+ "avg": 34.65519865830175,
+ "p(50)": 14.341025,
+ "p(95)": 88.761411
+ },
+ "checks": {
+ "passes": 110481,
+ "fails": 0,
+ "value": 1
+ },
+ "http_req_duration": {
+ "avg": 34.65519865830175,
+ "p(50)": 14.341025,
+ "p(95)": 88.761411,
+ "p(99)": 95.42866276000001,
+ "max": 173.13552
+ },
+ "vus": {
+ "value": 128,
+ "min": 0,
+ "max": 128
+ },
+ "iteration_duration": {
+ "p(95)": 88.904111,
+ "p(99)": 95.5377824,
+ "max": 173.202494,
+ "avg": 34.79765567884086,
+ "p(50)": 14.465018
+ },
+ "http_req_sending": {
+ "avg": 0.017846084375593648,
+ "p(50)": 0.006866,
+ "p(95)": 0.013960199999999997,
+ "p(99)": 0.12771492000000226,
+ "max": 8.722854
+ },
+ "http_req_blocked": {
+ "max": 29.894033,
+ "avg": 0.009463720692368238,
+ "p(50)": 0.001714,
+ "p(95)": 0.003085,
+ "p(99)": 0.008916360000000205
+ },
+ "data_received": {
+ "count": 179705953,
+ "rate": 5678261.298721273
+ },
+ "data_sent": {
+ "rate": 975173.4930802721,
+ "count": 30862349
+ },
+ "iterations": {
+ "count": 110481,
+ "rate": 3490.92490299431
+ },
+ "http_req_waiting": {
+ "avg": 34.56713911089098,
+ "p(50)": 14.252565,
+ "p(95)": 88.6658704,
+ "p(99)": 95.36470832000002,
+ "max": 173.11708
+ },
+ "http_reqs": {
+ "count": 110577,
+ "rate": 3493.9582643024755
+ },
+ "http_req_tls_handshaking": {
+ "avg": 0,
+ "p(50)": 0,
+ "p(95)": 0,
+ "p(99)": 0,
+ "max": 0
+ },
+ "vus_max": {
+ "max": 128,
+ "value": 128,
+ "min": 128
+ },
+ "http_req_failed": {
+ "passes": 0,
+ "fails": 110577,
+ "value": 0
+ },
+ "http_req_receiving": {
+ "max": 24.690931,
+ "avg": 0.07021346303480801,
+ "p(50)": 0.023,
+ "p(95)": 0.1859996,
+ "p(99)": 1.304737240000009
+ }
+ },
+ "root_group": {
+ "name": "",
+ "path": "",
+ "id": "d41d8cd98f00b204e9800998ecf8427e",
+ "groups": {},
+ "checks": {
+ "post 201": {
+ "id": "b533583d1cfe2cae9c2495a0b78acdf9",
+ "passes": 77332,
+ "fails": 0,
+ "name": "post 201",
+ "path": "::post 201"
+ },
+ "get 200": {
+ "name": "get 200",
+ "path": "::get 200",
+ "id": "2c445af86d719d43e970db9ef11acf1c",
+ "passes": 33149,
+ "fails": 0
+ }
+ }
+ }
+}
diff --git a/evidence/track1/results.json b/evidence/track1/results.json
new file mode 100644
index 00000000..f64b13fa
--- /dev/null
+++ b/evidence/track1/results.json
@@ -0,0 +1,624 @@
+{
+ "f1x2.0": {
+ "replicas": 1,
+ "cpus_per_replica": "2.0",
+ "mem_per_replica": "512M",
+ "db_pool_per_replica": 20,
+ "extra_env": {},
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 3635.6,
+ "min": 3271.5,
+ "max": 3835.0
+ },
+ "p50_ms": {
+ "mean": 26.6,
+ "min": 25.7,
+ "max": 27.2
+ },
+ "p95_ms": {
+ "mean": 63.7,
+ "min": 58.1,
+ "max": 71.8
+ },
+ "p99_ms": {
+ "mean": 71.6,
+ "min": 66.7,
+ "max": 77.9
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 178.6,
+ "postgres": 171.2,
+ "lb": 39.9,
+ "valkey": 7.4
+ },
+ "api_cpu_max_one_replica_pct": 209.1,
+ "mem_mib": {
+ "api": 36.7,
+ "postgres": 299.2,
+ "lb": 33.4,
+ "valkey": 6.7
+ },
+ "pg_active_backends": 13.0,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 10.93,
+ "IO:WalSync": 0.81,
+ "CPU:-": 0.71,
+ "Client:ClientRead": 0.54
+ }
+ },
+ "f2x1.0": {
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 3536.8,
+ "min": 3518.7,
+ "max": 3571.6
+ },
+ "p50_ms": {
+ "mean": 30.2,
+ "min": 29.7,
+ "max": 30.6
+ },
+ "p95_ms": {
+ "mean": 79.4,
+ "min": 75.4,
+ "max": 82.7
+ },
+ "p99_ms": {
+ "mean": 91.3,
+ "min": 88.1,
+ "max": 93.3
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 181.5,
+ "postgres": 153.7,
+ "lb": 42.3,
+ "valkey": 8.0
+ },
+ "api_cpu_max_one_replica_pct": 105.8,
+ "mem_mib": {
+ "api": 54.1,
+ "postgres": 317.8,
+ "lb": 33.8,
+ "valkey": 6.9
+ },
+ "pg_active_backends": 10.7,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 8.8,
+ "CPU:-": 0.86,
+ "IO:WalSync": 0.66,
+ "Client:ClientRead": 0.39
+ }
+ },
+ "f4x0.5": {
+ "replicas": 4,
+ "cpus_per_replica": "0.5",
+ "mem_per_replica": "128M",
+ "db_pool_per_replica": 5,
+ "extra_env": {},
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 3110.2,
+ "min": 2984.8,
+ "max": 3203.5
+ },
+ "p50_ms": {
+ "mean": 31.3,
+ "min": 28.4,
+ "max": 33.3
+ },
+ "p95_ms": {
+ "mean": 96.7,
+ "min": 91.0,
+ "max": 102.5
+ },
+ "p99_ms": {
+ "mean": 121.9,
+ "min": 118.0,
+ "max": 127.2
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 187.2,
+ "postgres": 146.1,
+ "lb": 40.5,
+ "valkey": 7.9
+ },
+ "api_cpu_max_one_replica_pct": 53.2,
+ "mem_mib": {
+ "api": 84.8,
+ "postgres": 348.3,
+ "lb": 34.0,
+ "valkey": 7.1
+ },
+ "pg_active_backends": 10.6,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 8.67,
+ "IO:WalSync": 0.86,
+ "CPU:-": 0.69,
+ "Client:ClientRead": 0.36
+ }
+ },
+ "g1": {
+ "replicas": 1,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 2050.9,
+ "min": 2033.3,
+ "max": 2065.0
+ },
+ "p50_ms": {
+ "mean": 55.4,
+ "min": 54.8,
+ "max": 56.0
+ },
+ "p95_ms": {
+ "mean": 86.8,
+ "min": 86.5,
+ "max": 87.3
+ },
+ "p99_ms": {
+ "mean": 95.0,
+ "min": 94.6,
+ "max": 95.8
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 95.2,
+ "postgres": 82.3,
+ "lb": 21.8,
+ "valkey": 4.2
+ },
+ "api_cpu_max_one_replica_pct": 104.0,
+ "mem_mib": {
+ "api": 28.7,
+ "postgres": 464.5,
+ "lb": 33.6,
+ "valkey": 6.7
+ },
+ "pg_active_backends": 5.6,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 4.35,
+ "IO:WalSync": 0.73,
+ "CPU:-": 0.42,
+ "Client:ClientRead": 0.1
+ }
+ },
+ "g2": {
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 3439.8,
+ "min": 3264.1,
+ "max": 3563.8
+ },
+ "p50_ms": {
+ "mean": 31.5,
+ "min": 30.5,
+ "max": 33.4
+ },
+ "p95_ms": {
+ "mean": 76.8,
+ "min": 74.3,
+ "max": 81.2
+ },
+ "p99_ms": {
+ "mean": 88.5,
+ "min": 85.9,
+ "max": 92.9
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 188.2,
+ "postgres": 161.3,
+ "lb": 43.9,
+ "valkey": 8.0
+ },
+ "api_cpu_max_one_replica_pct": 106.7,
+ "mem_mib": {
+ "api": 51.6,
+ "postgres": 513.3,
+ "lb": 34.3,
+ "valkey": 6.8
+ },
+ "pg_active_backends": 9.3,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 7.73,
+ "IO:WalSync": 0.79,
+ "CPU:-": 0.54,
+ "Client:ClientRead": 0.21
+ }
+ },
+ "g4": {
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 3644.9,
+ "min": 3558.6,
+ "max": 3740.2
+ },
+ "p50_ms": {
+ "mean": 18.5,
+ "min": 17.9,
+ "max": 19.7
+ },
+ "p95_ms": {
+ "mean": 85.8,
+ "min": 84.5,
+ "max": 87.6
+ },
+ "p99_ms": {
+ "mean": 95.6,
+ "min": 94.5,
+ "max": 97.5
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 198.4,
+ "postgres": 187.2,
+ "lb": 46.7,
+ "valkey": 9.1
+ },
+ "api_cpu_max_one_replica_pct": 58.0,
+ "mem_mib": {
+ "api": 90.9,
+ "postgres": 584.0,
+ "lb": 34.4,
+ "valkey": 7.3
+ },
+ "pg_active_backends": 28.4,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 24.38,
+ "CPU:-": 1.92,
+ "Client:ClientRead": 1.11,
+ "IO:WalSync": 0.92
+ }
+ },
+ "g8": {
+ "replicas": 8,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {},
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 3407.9,
+ "min": 3333.7,
+ "max": 3494.0
+ },
+ "p50_ms": {
+ "mean": 14.1,
+ "min": 13.7,
+ "max": 14.3
+ },
+ "p95_ms": {
+ "mean": 89.1,
+ "min": 88.8,
+ "max": 89.4
+ },
+ "p99_ms": {
+ "mean": 96.7,
+ "min": 95.4,
+ "max": 98.8
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 185.3,
+ "postgres": 180.4,
+ "lb": 47.1,
+ "valkey": 8.1
+ },
+ "api_cpu_max_one_replica_pct": 28.9,
+ "mem_mib": {
+ "api": 175.4,
+ "postgres": 675.8,
+ "lb": 34.3,
+ "valkey": 7.9
+ },
+ "pg_active_backends": 48.3,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 40.36,
+ "CPU:-": 3.04,
+ "Client:ClientRead": 2.71,
+ "LWLock:BufferContent": 1.18
+ }
+ },
+ "g2-oneshot": {
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "oneshot"
+ },
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 4579.4,
+ "min": 4452.8,
+ "max": 4680.8
+ },
+ "p50_ms": {
+ "mean": 23.6,
+ "min": 23.3,
+ "max": 24.1
+ },
+ "p95_ms": {
+ "mean": 61.4,
+ "min": 58.4,
+ "max": 64.1
+ },
+ "p99_ms": {
+ "mean": 76.5,
+ "min": 73.3,
+ "max": 79.0
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 165.7,
+ "postgres": 179.2,
+ "lb": 56.0,
+ "valkey": 10.6
+ },
+ "api_cpu_max_one_replica_pct": 97.5,
+ "mem_mib": {
+ "api": 52.9,
+ "postgres": 582.9,
+ "lb": 34.7,
+ "valkey": 7.0
+ },
+ "pg_active_backends": 16.4,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 13.55,
+ "CPU:-": 1.56,
+ "IO:WalSync": 0.92,
+ "Client:ClientRead": 0.31
+ }
+ },
+ "g2-tx": {
+ "replicas": 2,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "tx"
+ },
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 3390.4,
+ "min": 3373.6,
+ "max": 3418.7
+ },
+ "p50_ms": {
+ "mean": 32.1,
+ "min": 31.5,
+ "max": 32.5
+ },
+ "p95_ms": {
+ "mean": 80.0,
+ "min": 73.4,
+ "max": 85.3
+ },
+ "p99_ms": {
+ "mean": 91.0,
+ "min": 84.0,
+ "max": 95.9
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 188.3,
+ "postgres": 165.0,
+ "lb": 42.3,
+ "valkey": 8.4
+ },
+ "api_cpu_max_one_replica_pct": 106.3,
+ "mem_mib": {
+ "api": 53.6,
+ "postgres": 562.4,
+ "lb": 34.4,
+ "valkey": 6.9
+ },
+ "pg_active_backends": 9.4,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 7.81,
+ "IO:WalSync": 0.79,
+ "CPU:-": 0.5,
+ "Client:ClientRead": 0.31
+ }
+ },
+ "g4-oneshot": {
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "oneshot"
+ },
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 4300.8,
+ "min": 4241.1,
+ "max": 4350.3
+ },
+ "p50_ms": {
+ "mean": 15.5,
+ "min": 15.3,
+ "max": 15.8
+ },
+ "p95_ms": {
+ "mean": 79.0,
+ "min": 77.9,
+ "max": 80.0
+ },
+ "p99_ms": {
+ "mean": 91.8,
+ "min": 91.1,
+ "max": 92.3
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 163.9,
+ "postgres": 182.1,
+ "lb": 54.2,
+ "valkey": 11.2
+ },
+ "api_cpu_max_one_replica_pct": 49.7,
+ "mem_mib": {
+ "api": 92.1,
+ "postgres": 616.1,
+ "lb": 34.6,
+ "valkey": 7.2
+ },
+ "pg_active_backends": 30.6,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 26.9,
+ "CPU:-": 2.06,
+ "IO:WalSync": 0.92,
+ "Client:ClientRead": 0.58
+ }
+ },
+ "g4-tx": {
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "tx"
+ },
+ "repeats": 3,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 3473.8,
+ "min": 3248.5,
+ "max": 3600.0
+ },
+ "p50_ms": {
+ "mean": 18.6,
+ "min": 17.4,
+ "max": 19.9
+ },
+ "p95_ms": {
+ "mean": 87.6,
+ "min": 84.6,
+ "max": 89.5
+ },
+ "p99_ms": {
+ "mean": 96.9,
+ "min": 94.5,
+ "max": 99.5
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 195.1,
+ "postgres": 187.7,
+ "lb": 47.1,
+ "valkey": 8.3
+ },
+ "api_cpu_max_one_replica_pct": 58.0,
+ "mem_mib": {
+ "api": 90.5,
+ "postgres": 615.5,
+ "lb": 34.4,
+ "valkey": 7.1
+ },
+ "pg_active_backends": 30.3,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 26.13,
+ "CPU:-": 1.73,
+ "Client:ClientRead": 1.37,
+ "IO:WalSync": 0.9
+ }
+ },
+ "g4-tx-k6cpu8": {
+ "replicas": 4,
+ "cpus_per_replica": "1.0",
+ "mem_per_replica": "256M",
+ "db_pool_per_replica": 10,
+ "extra_env": {
+ "MESSAGE_WRITE_PATH": "tx"
+ },
+ "repeats": 1,
+ "vus": 128,
+ "duration": "30s",
+ "rps": {
+ "mean": 3516.0,
+ "min": 3516.0,
+ "max": 3516.0
+ },
+ "p50_ms": {
+ "mean": 18.9,
+ "min": 18.9,
+ "max": 18.9
+ },
+ "p95_ms": {
+ "mean": 85.9,
+ "min": 85.9,
+ "max": 85.9
+ },
+ "p99_ms": {
+ "mean": 95.8,
+ "min": 95.8,
+ "max": 95.8
+ },
+ "error_ratio_max": 0,
+ "cpu_pct": {
+ "api": 196.7,
+ "postgres": 186.8,
+ "lb": 48.0,
+ "valkey": 8.3
+ },
+ "api_cpu_max_one_replica_pct": 56.5,
+ "mem_mib": {
+ "api": 89.8,
+ "postgres": 598.5,
+ "lb": 34.5,
+ "valkey": 6.9
+ },
+ "pg_active_backends": 27.1,
+ "pg_top_waits": {
+ "LWLock:WALWriteLock": 23.19,
+ "CPU:-": 1.5,
+ "Client:ClientRead": 1.5,
+ "IO:WalSync": 0.94
+ }
+ }
+}
diff --git a/evidence/track1/summary.md b/evidence/track1/summary.md
new file mode 100644
index 00000000..41184c45
--- /dev/null
+++ b/evidence/track1/summary.md
@@ -0,0 +1,14 @@
+| Конфигурация | Реплики × CPU / RAM, пул | RPS mean (min–max) | p50 / p95 / p99, мс | ошибки | CPU% api / pg / lb | PG active, топ ожиданий |
+| --- | --- | --- | --- | --- | --- | --- |
+| f1x2.0 | 1 × 2.0 / 512M, 20 | 3635.6 (3271.5–3835) | 26.6 / 63.7 / 71.6 | 0 | 178.6 / 171.2 / 39.9 | 13; LWLock:WALWriteLock 10.93, IO:WalSync 0.81 |
+| f2x1.0 | 2 × 1.0 / 256M, 10 | 3536.8 (3518.7–3571.6) | 30.2 / 79.4 / 91.3 | 0 | 181.5 / 153.7 / 42.3 | 10.7; LWLock:WALWriteLock 8.8, CPU:- 0.86 |
+| f4x0.5 | 4 × 0.5 / 128M, 5 | 3110.2 (2984.8–3203.5) | 31.3 / 96.7 / 121.9 | 0 | 187.2 / 146.1 / 40.5 | 10.6; LWLock:WALWriteLock 8.67, IO:WalSync 0.86 |
+| g1 | 1 × 1.0 / 256M, 10 | 2050.9 (2033.3–2065) | 55.4 / 86.8 / 95 | 0 | 95.2 / 82.3 / 21.8 | 5.6; LWLock:WALWriteLock 4.35, IO:WalSync 0.73 |
+| g2 | 2 × 1.0 / 256M, 10 | 3439.8 (3264.1–3563.8) | 31.5 / 76.8 / 88.5 | 0 | 188.2 / 161.3 / 43.9 | 9.3; LWLock:WALWriteLock 7.73, IO:WalSync 0.79 |
+| g4 | 4 × 1.0 / 256M, 10 | 3644.9 (3558.6–3740.2) | 18.5 / 85.8 / 95.6 | 0 | 198.4 / 187.2 / 46.7 | 28.4; LWLock:WALWriteLock 24.38, CPU:- 1.92 |
+| g8 | 8 × 1.0 / 256M, 10 | 3407.9 (3333.7–3494) | 14.1 / 89.1 / 96.7 | 0 | 185.3 / 180.4 / 47.1 | 48.3; LWLock:WALWriteLock 40.36, CPU:- 3.04 |
+| g2-oneshot | 2 × 1.0 / 256M, 10 | 4579.4 (4452.8–4680.8) | 23.6 / 61.4 / 76.5 | 0 | 165.7 / 179.2 / 56 | 16.4; LWLock:WALWriteLock 13.55, CPU:- 1.56 |
+| g2-tx | 2 × 1.0 / 256M, 10 | 3390.4 (3373.6–3418.7) | 32.1 / 80 / 91 | 0 | 188.3 / 165 / 42.3 | 9.4; LWLock:WALWriteLock 7.81, IO:WalSync 0.79 |
+| g4-oneshot | 4 × 1.0 / 256M, 10 | 4300.8 (4241.1–4350.3) | 15.5 / 79 / 91.8 | 0 | 163.9 / 182.1 / 54.2 | 30.6; LWLock:WALWriteLock 26.9, CPU:- 2.06 |
+| g4-tx | 4 × 1.0 / 256M, 10 | 3473.8 (3248.5–3600) | 18.6 / 87.6 / 96.9 | 0 | 195.1 / 187.7 / 47.1 | 30.3; LWLock:WALWriteLock 26.13, CPU:- 1.73 |
+| g4-tx-k6cpu8 | 4 × 1.0 / 256M, 10 | 3516 (3516–3516) | 18.9 / 85.9 / 95.8 | 0 | 196.7 / 186.8 / 48 | 27.1; LWLock:WALWriteLock 23.19, CPU:- 1.5 |
diff --git a/evidence/validate.txt b/evidence/validate.txt
new file mode 100644
index 00000000..248343ee
--- /dev/null
+++ b/evidence/validate.txt
@@ -0,0 +1 @@
+PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
diff --git a/infra/haproxy/haproxy.cfg b/infra/haproxy/haproxy.cfg
new file mode 100644
index 00000000..225beb06
--- /dev/null
+++ b/infra/haproxy/haproxy.cfg
@@ -0,0 +1,45 @@
+global
+ log stdout format raw local0 info
+ maxconn 4096
+
+resolvers docker
+ nameserver dns 127.0.0.11:53
+ resolve_retries 3
+ timeout resolve 1s
+ timeout retry 1s
+ hold valid 2s
+ hold obsolete 5s
+ accepted_payload_size 8192
+
+defaults
+ mode http
+ log global
+ option httplog
+ option dontlognull
+ timeout connect 1s
+ timeout client 30s
+ timeout server 10s
+ timeout http-request 5s
+ timeout http-keep-alive 10s
+ timeout check 500ms
+ retries 2
+ retry-on conn-failure
+ option redispatch 1
+
+frontend public
+ bind :8080
+ default_backend api
+
+backend api
+ balance roundrobin
+ option httpchk GET /health/ready
+ http-check expect status 200
+ default-server check inter 1s fastinter 500ms downinter 1s fall 2 rise 2 init-addr none resolvers docker resolve-prefer ipv4
+ server-template api 8 api:8080
+
+frontend internal_stats
+ bind :8404
+ monitor-uri /healthz
+ stats enable
+ stats uri /stats
+ stats refresh 5s
diff --git a/infra/k6/track1.js b/infra/k6/track1.js
new file mode 100644
index 00000000..9e42066e
--- /dev/null
+++ b/infra/k6/track1.js
@@ -0,0 +1,60 @@
+import http from 'k6/http';
+import encoding from 'k6/encoding';
+import { check } from 'k6';
+import { Counter } from 'k6/metrics';
+
+const BASE = __ENV.BASE_URL || 'http://lb:8080';
+const USERS = parseInt(__ENV.USERS || '32');
+const RUN = __ENV.RUN_ID || String(Date.now());
+const non2xx = new Counter('non_2xx');
+
+export const options = {
+ scenarios: {
+ main: {
+ executor: 'constant-vus',
+ vus: parseInt(__ENV.VUS || '64'),
+ duration: __ENV.DURATION || '30s',
+ },
+ },
+ setupTimeout: '120s',
+ summaryTrendStats: ['avg', 'p(50)', 'p(95)', 'p(99)', 'max'],
+ discardResponseBodies: false,
+};
+
+export function setup() {
+ const users = [];
+ for (let i = 0; i < USERS; i++) {
+ const username = `t1_${RUN}_${i}`.slice(0, 32);
+ const password = `T3st-password-${RUN}-${i}`;
+ let r = http.post(`${BASE}/api/v1/users`, JSON.stringify({ username, display_name: `Load ${i}`, password }),
+ { headers: { 'Content-Type': 'application/json' } });
+ if (r.status !== 201) throw new Error(`create user: ${r.status}`);
+ const id = r.json('id');
+ r = http.post(`${BASE}/api/v1/auth/sessions`, null,
+ { headers: { Authorization: 'Basic ' + encoding.b64encode(`${username}:${password}`) } });
+ if (r.status !== 201) throw new Error(`login: ${r.status}`);
+ const token = r.json('token');
+ r = http.post(`${BASE}/api/v1/chats`, JSON.stringify({ title: `load ${i}`, member_ids: [id] }),
+ { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` } });
+ if (r.status !== 201) throw new Error(`create chat: ${r.status}`);
+ users.push({ token, chat: r.json('id') });
+ }
+ return { users };
+}
+
+export default function (data) {
+ const u = data.users[(__VU - 1) % data.users.length];
+ const auth = { Authorization: `Bearer ${u.token}` };
+ let r;
+ if (Math.random() < 0.7) {
+ r = http.post(`${BASE}/api/v1/chats/${u.chat}/messages`,
+ JSON.stringify({ text: `k6 ${__VU}-${__ITER}` }),
+ { headers: Object.assign({ 'Content-Type': 'application/json',
+ 'Idempotency-Key': `${RUN}-${__VU}-${__ITER}` }, auth), tags: { op: 'post' } });
+ check(r, { 'post 201': (x) => x.status === 201 });
+ } else {
+ r = http.get(`${BASE}/api/v1/chats/${u.chat}/messages?limit=20`, { headers: auth, tags: { op: 'get' } });
+ check(r, { 'get 200': (x) => x.status === 200 });
+ }
+ if (r.status < 200 || r.status >= 300) non2xx.add(1);
+}
diff --git a/infra/valkey/valkey.conf b/infra/valkey/valkey.conf
new file mode 100644
index 00000000..6e50813e
--- /dev/null
+++ b/infra/valkey/valkey.conf
@@ -0,0 +1,8 @@
+bind 0.0.0.0
+port 6379
+protected-mode yes
+save ""
+appendonly no
+maxmemory 64mb
+maxmemory-policy volatile-ttl
+include /run/secrets/valkey_auth
diff --git a/scripts/demo/idempotency.py b/scripts/demo/idempotency.py
new file mode 100644
index 00000000..5105ebd3
--- /dev/null
+++ b/scripts/demo/idempotency.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+import argparse
+import json
+import sys
+import threading
+import uuid
+from concurrent.futures import ThreadPoolExecutor
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[2] / 'tests'))
+from client import Client
+
+
+def main():
+ p = argparse.ArgumentParser()
+ p.add_argument('--base-url', default='http://localhost:8080')
+ p.add_argument('--parallel', type=int, default=20)
+ a = p.parse_args()
+ c = Client(a.base_url)
+ alice, bob, _eve, chat = c.bootstrap()
+ path = '/api/v1/chats/' + chat['id'] + '/messages'
+
+ r = c.call('POST', path, 400, actor=alice, body={'text': 'без ключа'})
+ print('1) POST без Idempotency-Key ->', r['status'], r['json']['error']['code'])
+
+ key = 'demo-' + uuid.uuid4().hex[:8]
+ r1 = c.message(alice, chat, 'Привет', key=key)
+ r2 = c.message(alice, chat, 'Привет', key=key)
+ print('2) ключ %s: первый ответ %s id=%s (реплика %s)' % (key, r1['status'], r1['json']['id'], r1['headers']['X-Instance-Id']))
+ print(' повтор того же: %s id=%s (реплика %s) -> %s' % (
+ r2['status'], r2['json']['id'], r2['headers']['X-Instance-Id'],
+ 'ТО ЖЕ сообщение' if r1['json'] == r2['json'] else 'ОШИБКА: другое'))
+
+ r = c.call('POST', path, 409, actor=alice, body={'text': 'Другой текст'}, headers={'Idempotency-Key': key})
+ print('3) тот же ключ, другое тело ->', r['status'], r['json']['error']['code'])
+
+ key = 'race-' + uuid.uuid4().hex[:8]
+ barrier = threading.Barrier(a.parallel)
+
+ def send(_):
+ local = Client(a.base_url)
+ barrier.wait()
+ x = local.message(alice, chat, 'Гонка', key=key)
+ return x['json']['id'], x['headers']['X-Instance-Id']
+
+ with ThreadPoolExecutor(a.parallel) as pool:
+ res = list(pool.map(send, range(a.parallel)))
+ ids = {i for i, _ in res}
+ inst = {s for _, s in res}
+ history = c.call('GET', path + '?limit=100', actor=bob, schema='MessagePage')['json']['items']
+ stored = [m for m in history if m['text'] == 'Гонка']
+ print('4) %d параллельных POST с ключом %s через реплики %s' % (a.parallel, key, sorted(inst)))
+ print(' разных id в ответах: %d; сообщений в истории: %d -> %s' % (
+ len(ids), len(stored), 'дублей нет' if len(ids) == 1 and len(stored) == 1 else 'ДУБЛЬ!'))
+ print('История чата:', json.dumps([m['text'] for m in history], ensure_ascii=False))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/scripts/demo/instances.py b/scripts/demo/instances.py
new file mode 100644
index 00000000..075ba925
--- /dev/null
+++ b/scripts/demo/instances.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+import argparse
+import collections
+import subprocess
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[2] / 'tests'))
+from client import Client
+
+
+def containers():
+ out = subprocess.run(['docker', 'ps', '--filter', 'label=com.docker.compose.service=api',
+ '--format', '{{.ID}} {{.Names}}'], capture_output=True, text=True).stdout
+ return dict(line.split(' ', 1) for line in out.split('\n') if line.strip())
+
+
+def main():
+ p = argparse.ArgumentParser()
+ p.add_argument('--base-url', default='http://localhost:8080')
+ p.add_argument('--n', type=int, default=10)
+ a = p.parse_args()
+ c = Client(a.base_url)
+ user = c.user('demo')
+ print('Пользователь %s вошёл ОДИН раз (токен не печатается).' % user['user']['username'])
+ names = containers()
+ seen = collections.Counter()
+ for i in range(1, a.n + 1):
+ r = c.call('GET', '/api/v1/users/me', actor=user, schema='User')
+ iid = r['headers']['X-Instance-Id']
+ seen[iid] += 1
+ print('запрос %2d -> 200, X-Instance-Id=%s (контейнер %s)' % (i, iid, names.get(iid, '?')))
+ print('Итого: %d разных реплик обслужили одну сессию: %s' % (len(seen), dict(seen)))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/scripts/failover_series.py b/scripts/failover_series.py
new file mode 100644
index 00000000..f4124f27
--- /dev/null
+++ b/scripts/failover_series.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+import argparse
+import json
+import threading
+import time
+from pathlib import Path
+
+from lab3lib import WriteLoad, api_containers, ps_snapshot, sh, wait_healthy
+
+
+def main():
+ p = argparse.ArgumentParser()
+ p.add_argument('--base-url', default='http://localhost:8080')
+ p.add_argument('--mode', choices=['stop', 'kill'], default='stop')
+ p.add_argument('--workers', type=int, default=8)
+ p.add_argument('--observe', type=float, default=12.0, help='seconds after the failure')
+ p.add_argument('--output', default=None)
+ a = p.parse_args()
+
+ replicas = [r for r in api_containers() if r['state'] == 'running']
+ assert len(replicas) >= 2, 'need >=2 running api replicas'
+ load = WriteLoad(a.base_url, workers=a.workers)
+ load.start()
+ time.sleep(5)
+ rounds = []
+ for r in replicas:
+ cid = r['id']
+ base = (time.monotonic() - 5, time.monotonic())
+ before = ps_snapshot()
+ t_fail = time.monotonic()
+ done = {}
+
+ def act():
+ sh('docker', a.mode, cid)
+ done['t'] = time.monotonic()
+ th = threading.Thread(target=act)
+ th.start()
+ time.sleep(a.observe)
+ th.join()
+ during = ps_snapshot()
+ t_restore = time.monotonic()
+ sh('docker', 'start', cid)
+ healthy = wait_healthy(cid, 60)
+ t_healthy = time.monotonic()
+ t_back = None
+ while time.monotonic() - t_healthy < 15:
+ if any(e[1] and e[2] == cid and e[0] > t_healthy for e in list(load.events)):
+ t_back = time.monotonic()
+ break
+ time.sleep(0.1)
+ time.sleep(3)
+
+ ev = [e for e in list(load.events) if t_fail <= e[0] < t_restore]
+ errs = [e for e in ev if not e[1]]
+ served_target = [e for e in ev if e[1] and e[2] == cid]
+ rounds.append({
+ 'replica_name': r['name'], 'instance_id': cid, 'action': 'docker ' + a.mode,
+ 'action_duration_s': round(done['t'] - t_fail, 2),
+ 'baseline_5s': load.window(*base),
+ 'after_failure': load.window(t_fail, t_restore),
+ 'first_1s_after_failure': load.window(t_fail, t_fail + 1),
+ 'last_error_after_failure_s': round(max(e[0] for e in errs) - t_fail, 2) if errs else None,
+ 'target_last_served_after_failure_s': round(max(e[0] + e[3] for e in served_target) - t_fail, 2) if served_target else None,
+ 'restored_healthy_after_s': round(t_healthy - t_restore, 2) if healthy else None,
+ 'restored_back_in_rotation_after_s': round(t_back - t_restore, 2) if t_back else None,
+ 'errors_sample': sorted({e[2] for e in errs})[:3],
+ 'docker_ps_before': before.splitlines(), 'docker_ps_during': during.splitlines(),
+ })
+ print(json.dumps({k: v for k, v in rounds[-1].items() if not k.startswith('docker_ps')}, ensure_ascii=False))
+ load.stop()
+ result = {'mode': a.mode, 'workers': a.workers, 'client_timeout_s': load.timeout,
+ 'total': load.window(load.t0, time.monotonic()), 'client_retries': load.retries,
+ 'rounds': rounds, 'data_check': load.verify_history(),
+ 'docker_ps_end': ps_snapshot().splitlines()}
+ print(json.dumps(result['data_check']))
+ ok = result['data_check']['lost_confirmed'] == 0 and result['data_check']['duplicate_texts'] == 0
+ print('PASS' if ok else 'FAIL', 'data integrity across', len(rounds), 'failures')
+ if a.output:
+ Path(a.output).write_text(json.dumps(result, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
+ raise SystemExit(0 if ok else 1)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/scripts/init_secrets.py b/scripts/init_secrets.py
new file mode 100644
index 00000000..44efd53f
--- /dev/null
+++ b/scripts/init_secrets.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+import secrets
+import shutil
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+SECRETS = ROOT / 'secrets'
+
+
+def write(name, value):
+ path = SECRETS / name
+ if path.exists():
+ print('keep secrets/' + name)
+ return path.read_text().strip()
+ path.write_bytes((value + '\n').encode('utf-8'))
+ print('created secrets/' + name)
+ return value
+
+
+def main():
+ SECRETS.mkdir(exist_ok=True)
+ pg = write('pg_password', secrets.token_urlsafe(24))
+ write('database_url', 'postgres://messenger:%s@postgres:5432/messenger?sslmode=disable' % pg)
+ vk_conf = SECRETS / 'valkey_auth.conf'
+ if vk_conf.exists():
+ vk = vk_conf.read_text().split()[-1]
+ print('keep secrets/valkey_auth.conf')
+ else:
+ vk = secrets.token_urlsafe(24)
+ write('valkey_auth.conf', 'requirepass ' + vk)
+ write('cache_url', 'redis://:%s@valkey:6379/0' % vk)
+ env = ROOT / '.env'
+ if not env.exists():
+ shutil.copy(ROOT / '.env.example', env)
+ print('created .env from .env.example')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/scripts/lab3lib.py b/scripts/lab3lib.py
new file mode 100644
index 00000000..c0960ab6
--- /dev/null
+++ b/scripts/lab3lib.py
@@ -0,0 +1,130 @@
+import json
+import subprocess
+import sys
+import threading
+import time
+import uuid
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(ROOT / 'tests'))
+from client import Client, Failure
+
+PROJECT = 'mtusi-lab3'
+
+
+def sh(*args, check=True):
+ r = subprocess.run(list(args), cwd=ROOT, capture_output=True, text=True, encoding='utf-8')
+ if check and r.returncode != 0:
+ raise RuntimeError('%s failed: %s' % (' '.join(args[:3]), r.stderr.strip()[:300]))
+ return r.stdout.strip()
+
+
+def api_containers(all_states=False):
+ out = sh('docker', 'ps', *(['-a'] if all_states else []), '--no-trunc',
+ '--filter', 'label=com.docker.compose.project=' + PROJECT,
+ '--filter', 'label=com.docker.compose.service=api',
+ '--format', '{{json .}}')
+ rows = []
+ for line in out.splitlines():
+ d = json.loads(line)
+ rows.append({'id': d['ID'][:12], 'name': d['Names'], 'state': d['State'], 'status': d['Status']})
+ return sorted(rows, key=lambda r: r['name'])
+
+
+def health(cid):
+ return sh('docker', 'inspect', '-f', '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}', cid)
+
+
+def wait_healthy(cid, timeout=60):
+ deadline = time.monotonic() + timeout
+ while time.monotonic() < deadline:
+ if health(cid) == 'healthy':
+ return True
+ time.sleep(0.25)
+ return False
+
+
+def ps_snapshot():
+ return sh('docker', 'compose', 'ps', '-a', '--format', '{{.Name}}\t{{.State}}\t{{.Status}}')
+
+
+class WriteLoad:
+
+ def __init__(self, base_url, workers=8, timeout=2.0, pause=0.0):
+ self.base = base_url
+ self.workers = workers
+ self.timeout = timeout
+ self.pause = pause
+ self.events = []
+ self.confirmed = []
+ self.retries = 0
+ self._lock = threading.Lock()
+ self._stop = threading.Event()
+ self._threads = []
+ c = Client(base_url, timeout=10)
+ self.alice, self.bob, _eve, self.chat = c.bootstrap()
+ self.reader = c
+
+ def _worker(self, wid):
+ c = Client(self.base, timeout=self.timeout)
+ key = text = None
+ n = 0
+ while not self._stop.is_set():
+ if key is None:
+ key = uuid.uuid4().hex
+ text = 'load-%d-%d-%s' % (wid, n, key[:8])
+ start = time.monotonic()
+ try:
+ r = c.message(self.alice, self.chat, text, key=key)
+ with self._lock:
+ self.events.append((start, True, r['headers']['X-Instance-Id'], time.monotonic() - start))
+ self.confirmed.append(r['json'])
+ key = None
+ n += 1
+ except Failure as exc:
+ with self._lock:
+ self.events.append((start, False, str(exc)[-60:], time.monotonic() - start))
+ self.retries += 1
+ time.sleep(0.05)
+ if self.pause:
+ time.sleep(self.pause)
+
+ def start(self):
+ for i in range(self.workers):
+ t = threading.Thread(target=self._worker, args=(i,), daemon=True)
+ t.start()
+ self._threads.append(t)
+ self.t0 = time.monotonic()
+
+ def stop(self):
+ self._stop.set()
+ for t in self._threads:
+ t.join(timeout=15)
+
+ def window(self, a, b):
+ ev = [e for e in self.events if a <= e[0] < b]
+ ok = [e for e in ev if e[1]]
+ lat = sorted(e[3] for e in ok)
+ pct = lambda p: round(1000 * lat[min(len(lat) - 1, int(p * len(lat)))], 1) if lat else None
+ return {'seconds': round(b - a, 2), 'ok': len(ok), 'errors': len(ev) - len(ok),
+ 'ok_rps': round(len(ok) / (b - a), 1) if b > a else None,
+ 'p50_ms': pct(.5), 'p95_ms': pct(.95), 'p99_ms': pct(.99)}
+
+ def verify_history(self):
+ items, cursor = [], None
+ path = '/api/v1/chats/' + self.chat['id'] + '/messages?limit=100'
+ while True:
+ page = self.reader.call('GET', path + ('&cursor=' + cursor if cursor else ''),
+ actor=self.bob, schema='MessagePage')['json']
+ items += page['items']
+ cursor = page['next_cursor']
+ if not cursor:
+ break
+ by_id = {m['id']: m for m in items}
+ texts = [m['text'] for m in items]
+ lost = [m for m in self.confirmed if by_id.get(m['id']) != m]
+ return {'stored_messages': len(items), 'confirmed_201': len(self.confirmed),
+ 'lost_confirmed': len(lost), 'duplicate_ids': len(items) - len(by_id),
+ 'duplicate_texts': len(texts) - len(set(texts)),
+ 'unique_confirmed': len({m['id'] for m in self.confirmed})}
diff --git a/scripts/restart.cmd b/scripts/restart.cmd
new file mode 100644
index 00000000..4f1f02ad
--- /dev/null
+++ b/scripts/restart.cmd
@@ -0,0 +1,5 @@
+@echo off
+cd /d "%~dp0.."
+docker compose stop lb api || exit /b 1
+docker compose restart postgres valkey || exit /b 1
+docker compose start api lb || exit /b 1
diff --git a/scripts/restart.sh b/scripts/restart.sh
new file mode 100644
index 00000000..95790449
--- /dev/null
+++ b/scripts/restart.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+set -eu
+cd "$(dirname "$0")/.."
+docker compose stop lb api
+docker compose restart postgres valkey
+docker compose start api lb
diff --git a/scripts/rolling_update.py b/scripts/rolling_update.py
new file mode 100644
index 00000000..d3c57075
--- /dev/null
+++ b/scripts/rolling_update.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python3
+import argparse
+import json
+import os
+import time
+from pathlib import Path
+
+from lab3lib import WriteLoad, api_containers, ps_snapshot, sh, wait_healthy
+
+
+def image_label(cid):
+ return sh('docker', 'inspect', '-f', '{{index .Config.Labels "org.opencontainers.image.revision"}}', cid)
+
+
+def main():
+ p = argparse.ArgumentParser()
+ p.add_argument('--base-url', default='http://localhost:8080')
+ p.add_argument('--build-label', default=time.strftime('rollout-%Y%m%dT%H%M%S'))
+ p.add_argument('--workers', type=int, default=8)
+ p.add_argument('--output', default=None)
+ a = p.parse_args()
+
+ old = [r for r in api_containers() if r['state'] == 'running']
+ n = len(old)
+ assert n >= 2, 'need >=2 running replicas'
+ log = []
+ say = lambda *x: (print(*x), log.append(' '.join(map(str, x))))
+ say('old replicas:', [(r['name'], r['id'], image_label(r['id'])) for r in old])
+
+ load = WriteLoad(a.base_url, workers=a.workers)
+ load.start()
+ time.sleep(5)
+ t_begin = time.monotonic()
+
+ env = dict(os.environ, APP_BUILD=a.build_label)
+ t = time.monotonic()
+ import subprocess
+ subprocess.run(['docker', 'compose', 'build', '-q', 'migrate'], check=True, env=env,
+ cwd=Path(__file__).resolve().parents[1])
+ say('built image with label', a.build_label, 'in %.1fs' % (time.monotonic() - t))
+ sh('docker', 'compose', 'run', '--rm', '--no-deps', 'migrate')
+ say('migrations applied once (advisory lock, idempotent)')
+
+ for r in old:
+ before = {x['id'] for x in api_containers()}
+ sh('docker', 'compose', 'up', '-d', '--no-deps', '--no-recreate', '--scale', 'api=%d' % (n + 1), 'api')
+ new = [x for x in api_containers() if x['id'] not in before]
+ assert len(new) == 1, 'expected exactly one new replica, got %s' % new
+ cid = new[0]['id']
+ assert wait_healthy(cid, 60), 'new replica not healthy'
+ t_h = time.monotonic()
+ while not any(e[1] and e[2] == cid and e[0] > t_h for e in list(load.events)):
+ assert time.monotonic() - t_h < 15, 'new replica not in LB rotation'
+ time.sleep(0.1)
+ say('new %s (%s) healthy and serving; label=%s' % (new[0]['name'], cid, image_label(cid)))
+ t_s = time.monotonic()
+ sh('docker', 'stop', '-t', '15', r['id'])
+ sh('docker', 'rm', r['id'])
+ say('old %s (%s) drained+removed in %.1fs' % (r['name'], r['id'], time.monotonic() - t_s))
+
+ t_end = time.monotonic()
+ time.sleep(5)
+ load.stop()
+ now = api_containers()
+ say('new replicas:', [(x['name'], x['id'], image_label(x['id'])) for x in now])
+ result = {
+ 'build_label': a.build_label, 'replicas': n, 'workers': a.workers,
+ 'before_rollout_5s': load.window(t_begin - 5, t_begin),
+ 'during_rollout': load.window(t_begin, t_end),
+ 'after_rollout_5s': load.window(t_end, t_end + 5),
+ 'client_retries': load.retries,
+ 'error_samples': sorted({e[2] for e in load.events if not e[1]})[:5],
+ 'all_new_label': all(image_label(x['id']) == a.build_label for x in now),
+ 'data_check': load.verify_history(), 'log': log, 'docker_ps_end': ps_snapshot().splitlines(),
+ }
+ print(json.dumps({k: result[k] for k in ('before_rollout_5s', 'during_rollout', 'after_rollout_5s',
+ 'client_retries', 'all_new_label', 'data_check')}, indent=1))
+ ok = result['all_new_label'] and result['data_check']['lost_confirmed'] == 0 \
+ and result['data_check']['duplicate_texts'] == 0 and len(now) == n
+ print('PASS' if ok else 'FAIL', 'rolling update')
+ if a.output:
+ Path(a.output).write_text(json.dumps(result, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
+ raise SystemExit(0 if ok else 1)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/scripts/stop-one.cmd b/scripts/stop-one.cmd
new file mode 100644
index 00000000..8facef6a
--- /dev/null
+++ b/scripts/stop-one.cmd
@@ -0,0 +1,10 @@
+@echo off
+setlocal
+cd /d "%~dp0.."
+if "%TARGET_INSTANCE_ID%"=="" exit /b 2
+echo %TARGET_INSTANCE_ID%| findstr /r /x "[0-9a-f][0-9a-f]*" >nul || exit /b 2
+set CID=
+for /f %%i in ('docker ps -q --filter "id=%TARGET_INSTANCE_ID%" --filter "label=com.docker.compose.project=mtusi-lab3" --filter "label=com.docker.compose.service=api"') do set CID=%%i
+if "%CID%"=="" exit /b 3
+docker stop -t 15 %CID% >nul || exit /b 1
+echo stopped api container %CID%
diff --git a/scripts/stop-one.sh b/scripts/stop-one.sh
new file mode 100644
index 00000000..a21fd749
--- /dev/null
+++ b/scripts/stop-one.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+set -eu
+cd "$(dirname "$0")/.."
+: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
+case "$TARGET_INSTANCE_ID" in
+ *[!0-9a-f]*) echo "unexpected instance id format" >&2; exit 2 ;;
+esac
+cid=$(docker ps -q --filter "id=$TARGET_INSTANCE_ID" \
+ --filter "label=com.docker.compose.project=mtusi-lab3" \
+ --filter "label=com.docker.compose.service=api")
+[ -n "$cid" ] || { echo "no running api replica matches" >&2; exit 3; }
+[ "$(printf '%s\n' "$cid" | wc -l)" -eq 1 ] || { echo "ambiguous id" >&2; exit 3; }
+docker stop -t 15 "$cid" >/dev/null
+echo "stopped api container $cid"
diff --git a/scripts/track1/report_track1.py b/scripts/track1/report_track1.py
new file mode 100644
index 00000000..43e5105d
--- /dev/null
+++ b/scripts/track1/report_track1.py
@@ -0,0 +1,190 @@
+#!/usr/bin/env python3
+import json
+import statistics as st
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[2]
+OUT = ROOT / 'evidence' / 'track1'
+RAW = OUT / 'raw'
+
+ORDER = ['f1x2.0', 'f2x1.0', 'f4x0.5', 'g1', 'g2', 'g4', 'g8']
+
+
+def load():
+ runs = [json.loads(p.read_text(encoding='utf-8')) for p in sorted(RAW.glob('*.json'))
+ if not p.name.endswith('.k6.json')]
+ groups = {}
+ for r in runs:
+ groups.setdefault(r['config'], []).append(r)
+ return groups
+
+
+def summarize(runs):
+ def agg(vals):
+ return {'mean': round(st.mean(vals), 1), 'min': round(min(vals), 1), 'max': round(max(vals), 1)}
+ first = runs[0]
+ svc = lambda name, key: [r['docker_stats'].get(name, {}).get(key, 0) for r in runs]
+ return {
+ 'replicas': first['replicas'], 'cpus_per_replica': first['cpus_per_replica'],
+ 'mem_per_replica': first['mem_per_replica'], 'db_pool_per_replica': first['db_pool_per_replica'],
+ 'extra_env': first.get('extra_env', {}), 'repeats': len(runs), 'vus': first['vus'],
+ 'duration': first['duration'],
+ 'rps': agg([r['rps'] for r in runs]),
+ 'p50_ms': agg([r['latency_ms']['p(50)'] for r in runs]),
+ 'p95_ms': agg([r['latency_ms']['p(95)'] for r in runs]),
+ 'p99_ms': agg([r['latency_ms']['p(99)'] for r in runs]),
+ 'error_ratio_max': max(r['error_ratio'] for r in runs),
+ 'cpu_pct': {s: round(st.mean(svc(s, 'cpu_pct_mean')), 1) for s in ('api', 'postgres', 'lb', 'valkey')},
+ 'api_cpu_max_one_replica_pct': round(max(svc('api', 'cpu_pct_max_one_container')), 1),
+ 'mem_mib': {s: round(st.mean(svc(s, 'mem_mib_mean')), 1) for s in ('api', 'postgres', 'lb', 'valkey')},
+ 'pg_active_backends': round(st.mean(r['postgres']['active_backends_mean'] for r in runs), 1),
+ 'pg_top_waits': top_waits(runs),
+ }
+
+
+def top_waits(runs):
+ acc = {}
+ for r in runs:
+ for k, v in r['postgres']['wait_events_mean'].items():
+ acc[k] = acc.get(k, 0) + v / len(runs)
+ return {k: round(v, 2) for k, v in sorted(acc.items(), key=lambda x: -x[1])[:4]}
+
+
+FONT = 'font-family="system-ui,Segoe UI,Arial" font-size="12"'
+C1, C2, C3, C4 = '#2563eb', '#dc2626', '#16a34a', '#9333ea'
+
+
+def svg_wrap(w, h, body, title):
+ return ('\n'
+ % (w, h, w, h, FONT, w // 2, title, body))
+
+
+def axis(x0, y0, x1, y1, ymax, ylabel, ticks=5, right=False, color='#333'):
+ b = ''
+ xa = x1 if right else x0
+ for i in range(ticks + 1):
+ v = ymax * i / ticks
+ y = y1 - (y1 - y0) * i / ticks
+ if not right:
+ b += '' % (x0, y, x1, y)
+ b += '%g' % (
+ xa + (6 if right else -6), y + 4, 'start' if right else 'end', color, round(v, 1))
+ b += '%s' % (
+ xa + (48 if right else -48), (y0 + y1) // 2, color, ylabel)
+ return b
+
+
+def nice(v):
+ for e in range(0, 7):
+ for m in (1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8):
+ c = m * 10 ** e
+ if c >= v:
+ return c
+ return v
+
+
+def bar_chart(names, series, title, ylabel, path):
+ w, h, x0, y0, x1, y1 = 640, 380, 70, 40, 610, 300
+ ymax = nice(max(v[2] for _, _, vals in series for v in vals) * 1.1)
+ b = axis(x0, y0, x1, y1, ymax, ylabel)
+ gw = (x1 - x0) / len(names)
+ bw = gw * 0.7 / len(series)
+ for i, n in enumerate(names):
+ b += '%s' % (x0 + gw * (i + .5), y1 + 18, n)
+ for j, (lab, col, vals) in enumerate(series):
+ mean, lo, hi = vals[i]
+ x = x0 + gw * i + gw * 0.15 + bw * j
+ y = y1 - (y1 - y0) * mean / ymax
+ b += '' % (x, y, bw - 2, y1 - y, col)
+ ylo, yhi = (y1 - (y1 - y0) * v / ymax for v in (lo, hi))
+ cx = x + (bw - 2) / 2
+ b += '' % (cx, ylo, cx, yhi)
+ b += '%g' % (cx, y - 6 if yhi > y - 4 else yhi - 4, round(mean))
+ lx = x0
+ for lab, col, _ in series:
+ b += '%s' % (lx, y1 + 32, col, lx + 16, y1 + 42, lab)
+ lx += 20 + 8 * len(lab)
+ b += 'столбец = среднее, отрезок = min..max по повторам' % (x0, h - 8)
+ path.write_text(svg_wrap(w, h, b, title), encoding='utf-8')
+
+
+def line_chart(xs, left, right, title, xlabel, ylabel_l, ylabel_r, path, rmax=None):
+ w, h, x0, y0, x1, y1 = 680, 380, 80, 40, 600, 300
+ lmax = nice(max(v for _, _, vals, _ in left for v in vals) * 1.1)
+ rmax = rmax or nice(max(v for _, _, vals, _ in right for v in vals) * 1.1)
+ b = axis(x0, y0, x1, y1, lmax, ylabel_l) + axis(x0, y0, x1, y1, rmax, ylabel_r, right=True, color='#555')
+ px = lambda i: x0 + (x1 - x0) * i / (len(xs) - 1)
+ for i, x in enumerate(xs):
+ b += '%s' % (px(i), y1 + 18, x)
+ b += '%s' % ((x0 + x1) // 2, y1 + 36, xlabel)
+ for group, ymax in ((left, lmax), (right, rmax)):
+ for lab, col, vals, dashed in group:
+ pts = ' '.join('%.1f,%.1f' % (px(i), y1 - (y1 - y0) * v / ymax) for i, v in enumerate(vals))
+ b += '' % (
+ pts, col, ' stroke-dasharray="6 4"' if dashed else '')
+ for i, v in enumerate(vals):
+ b += '' % (px(i), y1 - (y1 - y0) * v / ymax, col)
+ lx = x0
+ for lab, col, _, dashed in left + right:
+ b += '%s' % (
+ lx, y1 + 56, lx + 18, y1 + 56, col, ' stroke-dasharray="6 4"' if dashed else '', lx + 22, y1 + 60, lab)
+ lx += 34 + 7 * len(lab)
+ path.write_text(svg_wrap(w, h, b, title), encoding='utf-8')
+
+
+def main():
+ groups = load()
+ res = {k: summarize(v) for k, v in groups.items()}
+ keys = [k for k in ORDER if k in res] + sorted(k for k in res if k not in ORDER)
+ (OUT / 'results.json').write_text(json.dumps({k: res[k] for k in keys}, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
+
+ lines = ['| Конфигурация | Реплики × CPU / RAM, пул | RPS mean (min–max) | p50 / p95 / p99, мс | ошибки | CPU% api / pg / lb | PG active, топ ожиданий |',
+ '| --- | --- | --- | --- | --- | --- | --- |']
+ for k in keys:
+ r = res[k]
+ lines.append('| %s | %d × %s / %s, %d | %g (%g–%g) | %g / %g / %g | %g | %g / %g / %g | %g; %s |' % (
+ k, r['replicas'], r['cpus_per_replica'], r['mem_per_replica'], r['db_pool_per_replica'],
+ r['rps']['mean'], r['rps']['min'], r['rps']['max'], r['p50_ms']['mean'], r['p95_ms']['mean'],
+ r['p99_ms']['mean'], r['error_ratio_max'], r['cpu_pct']['api'], r['cpu_pct']['postgres'],
+ r['cpu_pct']['lb'], r['pg_active_backends'],
+ ', '.join('%s %g' % kv for kv in list(r['pg_top_waits'].items())[:2])))
+ (OUT / 'summary.md').write_text('\n'.join(lines) + '\n', encoding='utf-8')
+ print('\n'.join(lines))
+
+ fixed = [k for k in ('f1x2.0', 'f2x1.0', 'f4x0.5') if k in res]
+ if fixed:
+ g = lambda key: [(res[k][key]['mean'], res[k][key]['min'], res[k][key]['max']) for k in fixed]
+ bar_chart(['1 × 2.0 CPU', '2 × 1.0 CPU', '4 × 0.5 CPU'][:len(fixed)], [('RPS', C1, g('rps'))],
+ 'Фиксированный бюджет API (2 CPU, 512 MiB, 20 соединений): RPS', 'успешные запросы/с', OUT / 'fixed-rps.svg')
+ bar_chart(['1 × 2.0 CPU', '2 × 1.0 CPU', '4 × 0.5 CPU'][:len(fixed)],
+ [('p50', C3, g('p50_ms')), ('p95', C1, g('p95_ms')), ('p99', C2, g('p99_ms'))],
+ 'Фиксированный бюджет API: задержка', 'мс', OUT / 'fixed-latency.svg')
+ growth = [k for k in ('g1', 'g2', 'g4', 'g8') if k in res]
+ if len(growth) >= 2:
+ xs = [res[k]['replicas'] for k in growth]
+ line_chart(xs, [('RPS', C1, [res[k]['rps']['mean'] for k in growth], False)],
+ [('CPU API (сумма)', C3, [res[k]['cpu_pct']['api'] for k in growth], True),
+ ('CPU PostgreSQL', C2, [res[k]['cpu_pct']['postgres'] for k in growth], True),
+ ('CPU HAProxy', C4, [res[k]['cpu_pct']['lb'] for k in growth], True)],
+ 'Рост числа реплик (по 1 CPU), PostgreSQL 2 CPU', 'API-реплик',
+ 'успешные запросы/с', 'CPU, % ядра', OUT / 'growth.svg')
+ line_chart(xs, [('p95, мс', C1, [res[k]['p95_ms']['mean'] for k in growth], False),
+ ('p99, мс', C2, [res[k]['p99_ms']['mean'] for k in growth], False)],
+ [('активных backend PG', C3, [res[k]['pg_active_backends'] for k in growth], True)],
+ 'Рост числа реплик: задержка и очередь в PostgreSQL', 'API-реплик', 'мс',
+ 'активные сессии PG', OUT / 'growth-latency.svg')
+ ab = [('g2-tx', 'g2-oneshot'), ('g4-tx', 'g4-oneshot')]
+ if all(k in res for pair in ab for k in pair):
+ g = lambda keys, m: [(res[k][m]['mean'], res[k][m]['min'], res[k][m]['max']) for k in keys]
+ bar_chart(['2 реплики', '4 реплики'], [('tx: 5 round trip', C2, g([a for a, _ in ab], 'rps')),
+ ('oneshot: 1 запрос', C3, g([b for _, b in ab], 'rps'))],
+ 'Улучшение: запись сообщения одним SQL-оператором', 'успешные запросы/с', OUT / 'improvement-rps.svg')
+ bar_chart(['2 реплики', '4 реплики'], [('tx p95', C2, g([a for a, _ in ab], 'p95_ms')),
+ ('oneshot p95', C3, g([b for _, b in ab], 'p95_ms'))],
+ 'Улучшение: p95 задержки', 'мс', OUT / 'improvement-p95.svg')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/scripts/track1/run_track1.py b/scripts/track1/run_track1.py
new file mode 100644
index 00000000..7c5d9f18
--- /dev/null
+++ b/scripts/track1/run_track1.py
@@ -0,0 +1,194 @@
+#!/usr/bin/env python3
+import argparse
+import json
+import os
+import re
+import subprocess
+import threading
+import time
+import urllib.request
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[2]
+RAW = ROOT / 'evidence' / 'track1' / 'raw'
+PROJECT = 'mtusi-lab3'
+
+SERIES = {
+ 'fixed': {'f1x2.0': (1, '2.0', '512M', 20), 'f2x1.0': (2, '1.0', '256M', 10), 'f4x0.5': (4, '0.5', '128M', 5)},
+ 'growth': {'g1': (1, '1.0', '256M', 10), 'g2': (2, '1.0', '256M', 10),
+ 'g4': (4, '1.0', '256M', 10), 'g8': (8, '1.0', '256M', 10)},
+}
+
+
+def sh(args, env=None, check=True):
+ r = subprocess.run(args, cwd=ROOT, capture_output=True, text=True, encoding='utf-8', env=env)
+ if check and r.returncode != 0:
+ raise RuntimeError(' '.join(args[:4]) + ': ' + r.stderr[-400:])
+ return r.stdout
+
+
+def compose_env(cfg, extra):
+ n, cpus, mem, pool = cfg
+ env = dict(os.environ, API_REPLICAS=str(n), API_CPUS=cpus, API_MEMORY=mem, DB_MAX_CONNS=str(pool))
+ env.update(extra)
+ return env
+
+
+def apply(cfg, extra):
+ env = compose_env(cfg, extra)
+ sh(['docker', 'compose', 'up', '-d', '--wait', '--force-recreate', '--no-deps', 'api'], env=env)
+ sh(['docker', 'compose', 'up', '-d', '--wait', '--no-deps', 'lb'], env=env)
+ deadline = time.monotonic() + 60
+ while time.monotonic() < deadline:
+ seen = set()
+ for _ in range(4 * cfg[0] + 4):
+ with urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2) as r:
+ seen.add(r.headers['X-Instance-Id'])
+ if len(seen) == cfg[0]:
+ return sorted(seen)
+ time.sleep(1)
+ raise RuntimeError('LB does not see %d replicas' % cfg[0])
+
+
+def parse_mem(s):
+ m = re.match(r'([\d.]+)\s*([KMG]i?B|B)', s.strip())
+ if not m:
+ return None
+ k = {'B': 1 / 2**20, 'KiB': 1 / 1024, 'KB': 1 / 1024, 'MiB': 1, 'MB': 1, 'GiB': 1024, 'GB': 1024}[m.group(2)]
+ return float(m.group(1)) * k
+
+
+class Sampler(threading.Thread):
+ def __init__(self):
+ super().__init__(daemon=True)
+ self.stop = threading.Event()
+ self.stats = []
+ self.pg = []
+
+ def run(self):
+ while not self.stop.is_set():
+ out = sh(['docker', 'stats', '--no-stream', '--format', '{{json .}}'], check=False)
+ snap = {}
+ for line in out.splitlines():
+ try:
+ d = json.loads(line)
+ except ValueError:
+ continue
+ m = re.match(PROJECT + r'-(\w+?)-\d+$', d['Name'])
+ if not m:
+ continue
+ cpu = float(d['CPUPerc'].rstrip('%') or 0)
+ s = snap.setdefault(m.group(1), {'cpu': 0.0, 'mem_mib': 0.0, 'max_cpu': 0.0, 'n': 0})
+ s['cpu'] += cpu
+ s['max_cpu'] = max(s['max_cpu'], cpu)
+ s['mem_mib'] += parse_mem(d['MemUsage'].split('/')[0]) or 0
+ s['n'] += 1
+ if snap:
+ self.stats.append(snap)
+ q = ("SELECT coalesce(wait_event_type,'CPU')||':'||coalesce(wait_event,'-'), count(*) "
+ "FROM pg_stat_activity WHERE state='active' AND backend_type='client backend' "
+ "AND pid<>pg_backend_pid() GROUP BY 1")
+ out = sh(['docker', 'compose', 'exec', '-T', 'postgres', 'psql', '-U', 'messenger', '-d', 'messenger',
+ '-At', '-F', '|', '-c', q], check=False)
+ waits = {}
+ for line in out.splitlines():
+ if '|' in line:
+ k, v = line.rsplit('|', 1)
+ waits[k] = int(v)
+ self.pg.append({'active': sum(waits.values()), 'waits': waits})
+
+
+K6_CPUS = '4'
+
+
+def k6(name, vus, duration, run_id, summary=None):
+ args = ['docker', 'run', '--rm', '--network', PROJECT + '_app', '--cpus', K6_CPUS,
+ '-v', str(ROOT / 'infra' / 'k6') + ':/scripts:ro',
+ '-e', 'VUS=%d' % vus, '-e', 'DURATION=' + duration, '-e', 'RUN_ID=' + run_id]
+ if summary:
+ args += ['-v', str(RAW) + ':/out']
+ args += ['grafana/k6:0.54.0', 'run', '--quiet']
+ if summary:
+ args += ['--summary-export', '/out/' + summary]
+ args += ['/scripts/track1.js']
+ env = dict(os.environ, MSYS_NO_PATHCONV='1')
+ sh(args, env=env)
+
+
+def aggregate(sampler):
+ svc = {}
+ for snap in sampler.stats:
+ for k, v in snap.items():
+ svc.setdefault(k, []).append(v)
+ out = {}
+ for k, vals in svc.items():
+ out[k] = {'cpu_pct_mean': round(sum(v['cpu'] for v in vals) / len(vals), 1),
+ 'cpu_pct_max_one_container': round(max(v['max_cpu'] for v in vals), 1),
+ 'mem_mib_mean': round(sum(v['mem_mib'] for v in vals) / len(vals), 1),
+ 'containers': vals[-1]['n']}
+ waits = {}
+ for s in sampler.pg:
+ for k, v in s['waits'].items():
+ waits[k] = waits.get(k, 0) + v
+ n = max(1, len(sampler.pg))
+ return out, {'samples': len(sampler.pg),
+ 'active_backends_mean': round(sum(s['active'] for s in sampler.pg) / n, 1),
+ 'wait_events_mean': {k: round(v / n, 2) for k, v in sorted(waits.items(), key=lambda x: -x[1])}}
+
+
+def main():
+ p = argparse.ArgumentParser()
+ p.add_argument('--series', choices=list(SERIES), required=True)
+ p.add_argument('--only', nargs='*', default=None, help='subset of config names')
+ p.add_argument('--repeat', type=int, default=3)
+ p.add_argument('--vus', type=int, default=128)
+ p.add_argument('--warmup', default='10s')
+ p.add_argument('--duration', default='30s')
+ p.add_argument('--tag', default='', help='suffix for an experiment variant, e.g. "-v2"')
+ p.add_argument('--env', nargs='*', default=[], help='extra compose env KEY=VALUE')
+ p.add_argument('--start-repeat', type=int, default=1, help='number of the first repeat (to interleave variants)')
+ p.add_argument('--k6-cpus', default='4')
+ a = p.parse_args()
+ global K6_CPUS
+ K6_CPUS = a.k6_cpus
+ RAW.mkdir(parents=True, exist_ok=True)
+ extra = dict(kv.split('=', 1) for kv in a.env)
+ cfgs = {k: v for k, v in SERIES[a.series].items() if not a.only or k in a.only}
+ for rep in range(a.start_repeat, a.start_repeat + a.repeat):
+ for name, cfg in cfgs.items():
+ label = '%s%s-r%d' % (name, a.tag, rep)
+ print('==', label, cfg, flush=True)
+ replicas = apply(cfg, extra)
+ k6(name, a.vus, a.warmup, 'w%s%d' % (name.replace('.', ''), int(time.time())))
+ sampler = Sampler()
+ sampler.start()
+ t0 = time.time()
+ run_id = 'm%s%d' % (name.replace('.', ''), int(t0))
+ k6(name, a.vus, a.duration, run_id, summary=label + '.k6.json')
+ sampler.stop.set()
+ sampler.join(timeout=20)
+ stats, pg = aggregate(sampler)
+ summary_path = RAW / (label + '.k6.json')
+ k6sum = json.loads(summary_path.read_text(encoding='utf-8'))
+ k6sum.pop('setup_data', None)
+ summary_path.write_text(json.dumps(k6sum, indent=2) + '\n', encoding='utf-8')
+ k = k6sum['metrics']
+ dur = k['http_req_duration']
+ rec = {'label': label, 'config': name + a.tag, 'series': a.series, 'repeat': rep,
+ 'replicas': cfg[0], 'cpus_per_replica': cfg[1], 'mem_per_replica': cfg[2],
+ 'db_pool_per_replica': cfg[3], 'extra_env': extra, 'k6_cpus': K6_CPUS, 'vus': a.vus, 'duration': a.duration,
+ 'started_unix': int(t0), 'instances': replicas,
+ 'rps': round(k['http_reqs']['rate'], 1),
+ 'error_ratio': round(k['http_req_failed']['value'], 6),
+ 'latency_ms': {q: round(dur[q], 2) for q in ('p(50)', 'p(95)', 'p(99)', 'max')},
+ 'docker_stats': stats, 'postgres': pg}
+ (RAW / (label + '.json')).write_text(json.dumps(rec, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
+ print(' rps=%s err=%s p95=%s api_cpu=%s pg_cpu=%s lb_cpu=%s pg_active=%s' % (
+ rec['rps'], rec['error_ratio'], rec['latency_ms']['p(95)'],
+ stats.get('api', {}).get('cpu_pct_mean'), stats.get('postgres', {}).get('cpu_pct_mean'),
+ stats.get('lb', {}).get('cpu_pct_mean'), pg['active_backends_mean']), flush=True)
+ apply((2, '1.0', '256M', 10), {})
+
+
+if __name__ == '__main__':
+ main()
diff --git a/src/cmd/server/main.go b/src/cmd/server/main.go
new file mode 100644
index 00000000..0b465ebe
--- /dev/null
+++ b/src/cmd/server/main.go
@@ -0,0 +1,206 @@
+package main
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "log/slog"
+ "net/http"
+ "os"
+ "os/signal"
+ "strconv"
+ "strings"
+ "sync/atomic"
+ "syscall"
+ "time"
+
+ "mtusi-messenger/internal/api"
+ "mtusi-messenger/internal/auth"
+ "mtusi-messenger/internal/cache"
+ "mtusi-messenger/internal/db"
+ "mtusi-messenger/internal/store"
+)
+
+func getenv(key, def string) string {
+ if v := os.Getenv(key); v != "" {
+ return v
+ }
+ return def
+}
+
+func getint(key string, def int) int {
+ v := os.Getenv(key)
+ if v == "" {
+ return def
+ }
+ n, err := strconv.Atoi(v)
+ if err != nil || n <= 0 {
+ fmt.Fprintf(os.Stderr, "invalid %s\n", key)
+ os.Exit(2)
+ }
+ return n
+}
+
+func secret(key string) (string, error) {
+ if path := os.Getenv(key + "_FILE"); path != "" {
+ b, err := os.ReadFile(path)
+ if err != nil {
+ return "", fmt.Errorf("read %s_FILE: %w", key, err)
+ }
+ return strings.TrimSpace(string(b)), nil
+ }
+ if v := os.Getenv(key); v != "" {
+ return v, nil
+ }
+ return "", fmt.Errorf("%s or %s_FILE is required", key, key)
+}
+
+func main() {
+ log := slog.New(slog.NewJSONHandler(os.Stdout, nil))
+ if err := run(log); err != nil {
+ log.Error("fatal", "error", err.Error())
+ os.Exit(1)
+ }
+}
+
+func openDB(ctx context.Context) (*store.Store, func(), error) {
+ dsn, err := secret("DATABASE_URL")
+ if err != nil {
+ return nil, nil, err
+ }
+ pool, err := db.Open(ctx, dsn, db.PoolOptions{MaxConns: int32(getint("DB_MAX_CONNS", 10))})
+ if err != nil {
+ return nil, nil, errors.New("database config is invalid")
+ }
+ return store.New(pool), pool.Close, nil
+}
+
+func run(log *slog.Logger) error {
+ ctx := context.Background()
+
+ if len(os.Args) > 1 && os.Args[1] == "migrate" {
+ dsn, err := secret("DATABASE_URL")
+ if err != nil {
+ return err
+ }
+ pool, err := db.Open(ctx, dsn, db.PoolOptions{MaxConns: 2})
+ if err != nil {
+ return errors.New("database config is invalid")
+ }
+ defer pool.Close()
+ mctx, cancel := context.WithTimeout(ctx, 60*time.Second)
+ defer cancel()
+ return db.Migrate(mctx, pool, log)
+ }
+
+ st, closeDB, err := openDB(ctx)
+ if err != nil {
+ return err
+ }
+ defer closeDB()
+
+ ttl := time.Duration(getint("SESSION_TTL_SECONDS", 3600)) * time.Second
+ cacheMaxTTL := time.Duration(getint("SESSION_CACHE_MAX_TTL_SECONDS", 60)) * time.Second
+
+ var sessCache auth.SessionCache
+ switch mode := getenv("SESSION_STORE", "postgres"); mode {
+ case "postgres":
+ case "valkey", "redis":
+ url, err := secret("CACHE_URL")
+ if err != nil {
+ return err
+ }
+ vk, err := cache.NewValkey(url)
+ if err != nil {
+ return errors.New("cache config is invalid")
+ }
+ defer vk.Close()
+ sessCache = vk
+ default:
+ return fmt.Errorf("unknown SESSION_STORE %q (postgres|valkey|redis)", mode)
+ }
+
+ hasher := auth.NewHasher(getint("PASSWORD_HASH_CONCURRENCY", 4))
+ sessions := auth.NewSessions(st, sessCache, ttl, cacheMaxTTL, log)
+
+ instanceID := getenv("INSTANCE_ID", "")
+ if instanceID == "" {
+ h, err := os.Hostname()
+ if err != nil || h == "" {
+ return errors.New("cannot determine instance id; set INSTANCE_ID")
+ }
+ instanceID = h
+ }
+ idemTTL := time.Duration(getint("IDEMPOTENCY_TTL_SECONDS", 86400)) * time.Second
+ writePath := getenv("MESSAGE_WRITE_PATH", api.WritePathOneShot)
+ if writePath != api.WritePathOneShot && writePath != api.WritePathTx {
+ return fmt.Errorf("unknown MESSAGE_WRITE_PATH %q (oneshot|tx)", writePath)
+ }
+ drainDelay := time.Duration(getint("SHUTDOWN_DRAIN_MS", 3000)) * time.Millisecond
+
+ ready := &atomic.Bool{}
+ ready.Store(true)
+
+ host := getenv("APP_HOST", "0.0.0.0")
+ port := getenv("APP_PORT", "8080")
+ addr := host + ":" + port
+ srv := api.NewServer(st, sessions, hasher, log, ready, api.Options{InstanceID: instanceID, IdempotencyTTL: idemTTL, WritePath: writePath})
+ httpSrv := &http.Server{
+ Addr: addr,
+ Handler: srv.Handler(),
+ ReadHeaderTimeout: 5 * time.Second,
+ ReadTimeout: 15 * time.Second,
+ WriteTimeout: 30 * time.Second,
+ IdleTimeout: 60 * time.Second,
+ }
+
+ bgCtx, stopBg := context.WithCancel(ctx)
+ defer stopBg()
+ go func() {
+ t := time.NewTicker(10 * time.Minute)
+ defer t.Stop()
+ for {
+ select {
+ case <-bgCtx.Done():
+ return
+ case <-t.C:
+ c, cancel := context.WithTimeout(bgCtx, 10*time.Second)
+ if n, err := st.PurgeSessions(c, 24*time.Hour); err == nil && n > 0 {
+ log.Info("expired sessions purged", "count", n)
+ }
+ if n, err := st.PurgeIdempotency(c, idemTTL); err == nil && n > 0 {
+ log.Info("expired idempotency keys purged", "count", n)
+ }
+ cancel()
+ }
+ }
+ }()
+
+ errCh := make(chan error, 1)
+ go func() { errCh <- httpSrv.ListenAndServe() }()
+ log.Info("server started", "addr", addr, "pid", os.Getpid(), "instance_id", instanceID, "build", getenv("APP_BUILD", "dev"), "write_path", writePath,
+ "session_store", getenv("SESSION_STORE", "postgres"), "session_ttl_s", int(ttl.Seconds()))
+
+ stop := make(chan os.Signal, 1)
+ signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT)
+
+ select {
+ case err := <-errCh:
+ if err != nil && !errors.Is(err, http.ErrServerClosed) {
+ return err
+ }
+ case sig := <-stop:
+ log.Info("shutdown signal received", "signal", sig.String())
+ ready.Store(false)
+ time.Sleep(drainDelay)
+ httpSrv.SetKeepAlivesEnabled(false)
+ sctx, cancel := context.WithTimeout(ctx, 5*time.Second)
+ defer cancel()
+ if err := httpSrv.Shutdown(sctx); err != nil {
+ log.Warn("graceful shutdown exceeded budget, closing", "error", err.Error())
+ _ = httpSrv.Close()
+ }
+ log.Info("server stopped cleanly")
+ }
+ return nil
+}
diff --git a/src/go.mod b/src/go.mod
new file mode 100644
index 00000000..e4a5be61
--- /dev/null
+++ b/src/go.mod
@@ -0,0 +1,21 @@
+module mtusi-messenger
+
+go 1.23
+
+require (
+ github.com/google/uuid v1.6.0
+ github.com/jackc/pgx/v5 v5.7.2
+ github.com/redis/go-redis/v9 v9.7.0
+ golang.org/x/crypto v0.31.0
+)
+
+require (
+ github.com/cespare/xxhash/v2 v2.2.0 // indirect
+ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
+ github.com/jackc/pgpassfile v1.0.0 // indirect
+ github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
+ github.com/jackc/puddle/v2 v2.2.2 // indirect
+ golang.org/x/sync v0.10.0 // indirect
+ golang.org/x/sys v0.28.0 // indirect
+ golang.org/x/text v0.21.0 // indirect
+)
diff --git a/src/go.sum b/src/go.sum
new file mode 100644
index 00000000..610cf610
--- /dev/null
+++ b/src/go.sum
@@ -0,0 +1,42 @@
+github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
+github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
+github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
+github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
+github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
+github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
+github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
+github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
+github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
+github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
+github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
+github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
+github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
+github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
+github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
+github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
+golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
+golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
+golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
+golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
+golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/src/internal/api/handlers.go b/src/internal/api/handlers.go
new file mode 100644
index 00000000..ba7bdf0e
--- /dev/null
+++ b/src/internal/api/handlers.go
@@ -0,0 +1,411 @@
+package api
+
+import (
+ "context"
+ "encoding/base64"
+ "errors"
+ "net/http"
+ "strings"
+ "time"
+ "unicode/utf8"
+
+ "mtusi-messenger/internal/apperr"
+ "mtusi-messenger/internal/auth"
+ "mtusi-messenger/internal/model"
+ "mtusi-messenger/internal/store"
+)
+
+func (s *Server) storeError(w http.ResponseWriter, r *http.Request, err error) {
+ id := requestID(r)
+ if store.IsUnavailable(err) || errors.Is(err, auth.ErrCacheUnavailable) {
+ s.log.Warn("dependency unavailable", "request_id", id, "error", err.Error())
+ apperr.Write(w, id, apperr.Unavailable("storage temporarily unavailable"))
+ return
+ }
+ s.log.Error("unexpected storage error", "request_id", id, "error", err.Error())
+ apperr.Write(w, id, apperr.Internal("internal error"))
+}
+
+func (s *Server) healthLive(w http.ResponseWriter, r *http.Request) {
+ writeJSON(w, r, http.StatusOK, model.Health{Status: "ok"})
+}
+
+func (s *Server) healthReady(w http.ResponseWriter, r *http.Request) {
+ if !s.ready.Load() {
+ apperr.Write(w, requestID(r), apperr.Unavailable("service is shutting down"))
+ return
+ }
+ ctx, cancel := context.WithTimeout(r.Context(), time.Second)
+ defer cancel()
+ if err := s.store.Ping(ctx); err != nil {
+ apperr.Write(w, requestID(r), apperr.Unavailable("database is not reachable"))
+ return
+ }
+ writeJSON(w, r, http.StatusOK, model.Health{Status: "ok"})
+}
+
+type createUserReq struct {
+ Username string `json:"username"`
+ DisplayName string `json:"display_name"`
+ Password string `json:"password"`
+}
+
+func validPassword(p string) bool {
+ n := utf8.RuneCountInString(p)
+ return utf8.ValidString(p) && n >= 12 && n <= 128
+}
+
+func (s *Server) usersRoute(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodPost {
+ methodNotAllowed(w, r)
+ return
+ }
+ id := requestID(r)
+ var req createUserReq
+ if aerr := decodeJSON(w, r, &req); aerr != nil {
+ apperr.Write(w, id, aerr)
+ return
+ }
+ if !usernameRe.MatchString(req.Username) {
+ apperr.Write(w, id, apperr.InvalidRequest("username must match ^[a-z0-9_]{3,32}$"))
+ return
+ }
+ if !validText(req.DisplayName, 100) {
+ apperr.Write(w, id, apperr.InvalidRequest("display_name must be 1..100 non-space code points"))
+ return
+ }
+ if !validPassword(req.Password) {
+ apperr.Write(w, id, apperr.InvalidRequest("password must be 12..128 code points"))
+ return
+ }
+ hash, err := s.hasher.Hash(r.Context(), req.Password)
+ if err != nil {
+ s.storeError(w, r, err)
+ return
+ }
+ u, err := s.store.CreateUser(r.Context(), req.Username, req.DisplayName, hash)
+ if errors.Is(err, store.ErrUsernameTaken) {
+ apperr.Write(w, id, apperr.Conflict("username is already taken"))
+ return
+ }
+ if err != nil {
+ s.storeError(w, r, err)
+ return
+ }
+ writeJSON(w, r, http.StatusCreated, u)
+}
+
+func (s *Server) me(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodGet {
+ methodNotAllowed(w, r)
+ return
+ }
+ writeJSON(w, r, http.StatusOK, currentUser(r))
+}
+
+const basicChallenge = `Basic realm="messenger", charset="UTF-8"`
+
+func unauthorizedBasic(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("WWW-Authenticate", basicChallenge)
+ apperr.Write(w, requestID(r), apperr.Unauthorized("invalid username or password"))
+}
+
+func parseBasic(r *http.Request) (string, string, bool) {
+ scheme, value, ok := strings.Cut(r.Header.Get("Authorization"), " ")
+ if !ok || !strings.EqualFold(scheme, "Basic") {
+ return "", "", false
+ }
+ raw, err := base64.StdEncoding.DecodeString(strings.TrimSpace(value))
+ if err != nil || !utf8.Valid(raw) {
+ return "", "", false
+ }
+ user, pass, ok := strings.Cut(string(raw), ":")
+ if !ok || !usernameRe.MatchString(user) || !validPassword(pass) {
+ return "", "", false
+ }
+ return user, pass, true
+}
+
+func (s *Server) createSession(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodPost {
+ methodNotAllowed(w, r)
+ return
+ }
+ username, password, ok := parseBasic(r)
+ if !ok {
+ unauthorizedBasic(w, r)
+ return
+ }
+ user, hash, err := s.store.Credentials(r.Context(), username)
+ if err != nil && !errors.Is(err, store.ErrNotFound) {
+ s.storeError(w, r, err)
+ return
+ }
+
+ valid, err := s.hasher.Verify(r.Context(), password, hash)
+ if err != nil {
+ s.storeError(w, r, err)
+ return
+ }
+ if !valid {
+ unauthorizedBasic(w, r)
+ return
+ }
+ token, expires, err := s.sessions.Create(r.Context(), user)
+ if err != nil {
+ s.storeError(w, r, err)
+ return
+ }
+ writeJSON(w, r, http.StatusCreated, model.Session{
+ Token: token, TokenType: "Bearer", ExpiresAt: model.NewTime(expires), User: *user,
+ })
+}
+
+func (s *Server) revokeSession(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodDelete {
+ methodNotAllowed(w, r)
+ return
+ }
+ err := s.sessions.Revoke(r.Context(), currentToken(r))
+ if errors.Is(err, auth.ErrInvalidSession) {
+ unauthorizedBearer(w, r)
+ return
+ }
+ if err != nil {
+ s.storeError(w, r, err)
+ return
+ }
+ w.Header().Set("X-Request-Id", requestID(r))
+ w.WriteHeader(http.StatusNoContent)
+}
+
+type createChatReq struct {
+ Title string `json:"title"`
+ MemberIDs []string `json:"member_ids"`
+}
+
+func (s *Server) chatsRoute(w http.ResponseWriter, r *http.Request) {
+ switch r.Method {
+ case http.MethodPost:
+ s.createChat(w, r)
+ case http.MethodGet:
+ s.listChats(w, r)
+ default:
+ methodNotAllowed(w, r)
+ }
+}
+
+func (s *Server) createChat(w http.ResponseWriter, r *http.Request) {
+ id := requestID(r)
+ var req createChatReq
+ if aerr := decodeJSON(w, r, &req); aerr != nil {
+ apperr.Write(w, id, aerr)
+ return
+ }
+ if !validText(req.Title, 100) {
+ apperr.Write(w, id, apperr.InvalidRequest("title must be 1..100 non-space code points"))
+ return
+ }
+ if len(req.MemberIDs) < 1 || len(req.MemberIDs) > 100 {
+ apperr.Write(w, id, apperr.InvalidRequest("member_ids must contain 1..100 items"))
+ return
+ }
+ seen := make(map[string]bool, len(req.MemberIDs))
+ for _, raw := range req.MemberIDs {
+ uid, err := parseUUID(raw)
+ if err != nil {
+ apperr.Write(w, id, apperr.InvalidRequest("member_ids must be UUID strings"))
+ return
+ }
+ if seen[uid] {
+ apperr.Write(w, id, apperr.InvalidRequest("duplicate member_id"))
+ return
+ }
+ seen[uid] = true
+ }
+ caller := currentUser(r)
+ if !seen[caller.ID] {
+ apperr.Write(w, id, apperr.InvalidRequest("creator must be included in member_ids"))
+ return
+ }
+
+ chat, err := s.store.CreateChat(r.Context(), caller.ID, req.Title, req.MemberIDs)
+ if errors.Is(err, store.ErrUnknownMember) {
+ apperr.Write(w, id, apperr.InvalidRequest("unknown member_id"))
+ return
+ }
+ if err != nil {
+ s.storeError(w, r, err)
+ return
+ }
+ writeJSON(w, r, http.StatusCreated, chat)
+}
+
+func (s *Server) listChats(w http.ResponseWriter, r *http.Request) {
+ id := requestID(r)
+ caller := currentUser(r)
+ limit, cur, aerr := pagingParams(r, caller.ID)
+ if aerr != nil {
+ apperr.Write(w, id, aerr)
+ return
+ }
+ items, more, err := s.store.ListChats(r.Context(), caller.ID, limit, cur)
+ if err != nil {
+ s.storeError(w, r, err)
+ return
+ }
+ page := model.Page[*model.Chat]{Items: items}
+ if more && len(items) > 0 {
+ last := items[len(items)-1]
+ encoded := store.EncodeCursor(store.Cursor{Scope: caller.ID, TS: last.CreatedAt.Time, ID: last.ID})
+ page.NextCursor = &encoded
+ }
+ writeJSON(w, r, http.StatusOK, page)
+}
+
+func (s *Server) chatRoute(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodGet {
+ methodNotAllowed(w, r)
+ return
+ }
+ id := requestID(r)
+ chatID, err := parseUUID(r.PathValue("chat_id"))
+ if err != nil {
+ apperr.Write(w, id, apperr.InvalidRequest("chat_id must be a UUID"))
+ return
+ }
+ chat, err := s.store.ChatForUser(r.Context(), chatID, currentUser(r).ID)
+ if errors.Is(err, store.ErrNotFound) {
+ apperr.Write(w, id, apperr.NotFound("chat not found or not accessible"))
+ return
+ }
+ if err != nil {
+ s.storeError(w, r, err)
+ return
+ }
+ writeJSON(w, r, http.StatusOK, chat)
+}
+
+type createMessageReq struct {
+ Text string `json:"text"`
+}
+
+func (s *Server) messagesRoute(w http.ResponseWriter, r *http.Request) {
+ switch r.Method {
+ case http.MethodPost:
+ s.createMessage(w, r)
+ case http.MethodGet:
+ s.listMessages(w, r)
+ default:
+ methodNotAllowed(w, r)
+ }
+}
+
+func (s *Server) chatAccess(w http.ResponseWriter, r *http.Request) (string, bool) {
+ id := requestID(r)
+ chatID, err := parseUUID(r.PathValue("chat_id"))
+ if err != nil {
+ apperr.Write(w, id, apperr.InvalidRequest("chat_id must be a UUID"))
+ return "", false
+ }
+ ok, err := s.store.IsMember(r.Context(), chatID, currentUser(r).ID)
+ if err != nil {
+ s.storeError(w, r, err)
+ return "", false
+ }
+ if !ok {
+ apperr.Write(w, id, apperr.NotFound("chat not found or not accessible"))
+ return "", false
+ }
+ return chatID, true
+}
+
+func (s *Server) createMessage(w http.ResponseWriter, r *http.Request) {
+ id := requestID(r)
+ var chatID string
+ if s.writePath == WritePathTx {
+ var ok bool
+ if chatID, ok = s.chatAccess(w, r); !ok {
+ return
+ }
+ } else {
+ var err error
+ if chatID, err = parseUUID(r.PathValue("chat_id")); err != nil {
+ apperr.Write(w, id, apperr.InvalidRequest("chat_id must be a UUID"))
+ return
+ }
+ }
+ reject := func(aerr *apperr.AppError) {
+ if s.writePath != WritePathTx {
+ if _, ok := s.chatAccess(w, r); !ok {
+ return
+ }
+ }
+ apperr.Write(w, id, aerr)
+ }
+ key := r.Header.Get("Idempotency-Key")
+ if !idempotencyKeyRe.MatchString(key) {
+ reject(apperr.InvalidRequest("Idempotency-Key header is required: [A-Za-z0-9._:-]{1,128}"))
+ return
+ }
+ var req createMessageReq
+ if aerr := decodeJSON(w, r, &req); aerr != nil {
+ reject(aerr)
+ return
+ }
+ if !validText(req.Text, 4000) {
+ reject(apperr.InvalidRequest("text must be 1..4000 non-space code points"))
+ return
+ }
+ add := s.store.AddMessageOneShot
+ if s.writePath == WritePathTx {
+ add = s.store.AddMessageIdempotent
+ }
+ msg, replayed, err := add(r.Context(), chatID, currentUser(r).ID, req.Text,
+ key, messageFingerprint(req), s.idempotencyTTL)
+ if errors.Is(err, store.ErrIdempotencyConflict) {
+ apperr.Write(w, id, apperr.Conflict("Idempotency-Key was already used with a different request"))
+ return
+ }
+ if errors.Is(err, store.ErrNotFound) {
+ apperr.Write(w, id, apperr.NotFound("chat not found or not accessible"))
+ return
+ }
+ if err != nil {
+ s.storeError(w, r, err)
+ return
+ }
+ if replayed {
+ w.Header().Set("Idempotent-Replayed", "true")
+ }
+ writeJSON(w, r, http.StatusCreated, msg)
+}
+
+func (s *Server) listMessages(w http.ResponseWriter, r *http.Request) {
+ id := requestID(r)
+ chatID, ok := s.chatAccess(w, r)
+ if !ok {
+ return
+ }
+ limit, cur, aerr := pagingParams(r, chatID)
+ if aerr != nil {
+ apperr.Write(w, id, aerr)
+ return
+ }
+ items, more, err := s.store.ListMessages(r.Context(), chatID, limit, cur)
+ if err != nil {
+ s.storeError(w, r, err)
+ return
+ }
+ page := model.Page[*model.Message]{Items: items}
+ if more && len(items) > 0 {
+ last := items[len(items)-1]
+ encoded := store.EncodeCursor(store.Cursor{Scope: chatID, TS: last.CreatedAt.Time, ID: last.ID})
+ page.NextCursor = &encoded
+ }
+ writeJSON(w, r, http.StatusOK, page)
+}
+
+func (s *Server) notFound(w http.ResponseWriter, r *http.Request) {
+ apperr.Write(w, requestID(r), apperr.NotFound("route not found"))
+}
diff --git a/src/internal/api/helpers.go b/src/internal/api/helpers.go
new file mode 100644
index 00000000..4ed2c6da
--- /dev/null
+++ b/src/internal/api/helpers.go
@@ -0,0 +1,110 @@
+package api
+
+import (
+ "crypto/sha256"
+ "encoding/json"
+ "errors"
+ "io"
+ "mime"
+ "net/http"
+ "regexp"
+ "strconv"
+ "strings"
+ "unicode/utf8"
+
+ "github.com/google/uuid"
+
+ "mtusi-messenger/internal/apperr"
+ "mtusi-messenger/internal/store"
+)
+
+const maxBodyBytes = 1 << 20
+
+var (
+ usernameRe = regexp.MustCompile(`^[a-z0-9_]{3,32}$`)
+ idempotencyKeyRe = regexp.MustCompile(`^[A-Za-z0-9._:-]{1,128}$`)
+)
+
+func messageFingerprint(req createMessageReq) []byte {
+ b, _ := json.Marshal(req)
+ sum := sha256.Sum256(b)
+ return sum[:]
+}
+
+func parseUUID(s string) (string, error) {
+ u, err := uuid.Parse(s)
+ if err != nil || u.String() != s {
+ return "", errors.New("invalid uuid")
+ }
+ return u.String(), nil
+}
+
+func runeLen(s string) int { return utf8.RuneCountInString(s) }
+
+func validText(s string, max int) bool {
+ n := runeLen(s)
+ return n >= 1 && n <= max && strings.TrimSpace(s) != ""
+}
+
+func decodeJSON(w http.ResponseWriter, r *http.Request, dst any) *apperr.AppError {
+ media, _, _ := mime.ParseMediaType(r.Header.Get("Content-Type"))
+ if media != "application/json" {
+ return apperr.UnsupportedMedia("Content-Type must be application/json")
+ }
+ r.Body = http.MaxBytesReader(w, r.Body, maxBodyBytes)
+ dec := json.NewDecoder(r.Body)
+ dec.DisallowUnknownFields()
+ if err := dec.Decode(dst); err != nil {
+ var maxErr *http.MaxBytesError
+ if errors.As(err, &maxErr) {
+ return apperr.PayloadTooLarge("request body too large")
+ }
+ return apperr.InvalidRequest("malformed JSON body")
+ }
+ var extra json.RawMessage
+ if err := dec.Decode(&extra); err != io.EOF {
+ var maxErr *http.MaxBytesError
+ if errors.As(err, &maxErr) {
+ return apperr.PayloadTooLarge("request body too large")
+ }
+ return apperr.InvalidRequest("malformed JSON body")
+ }
+ return nil
+}
+
+func pagingParams(r *http.Request, scope string) (int, *store.Cursor, *apperr.AppError) {
+ limit := 50
+ if v := r.URL.Query().Get("limit"); v != "" {
+ n, err := strconv.Atoi(v)
+ if err != nil || n < 1 || n > 100 {
+ return 0, nil, apperr.InvalidRequest("limit must be an integer in 1..100")
+ }
+ limit = n
+ }
+ var cur *store.Cursor
+ if v := r.URL.Query().Get("cursor"); v != "" {
+ c, err := store.DecodeCursor(v)
+ if err == nil {
+ _, err = parseUUID(c.ID)
+ }
+ if err != nil {
+ return 0, nil, apperr.InvalidRequest("invalid cursor")
+ }
+ if c.Scope != scope {
+ return 0, nil, apperr.InvalidRequest("cursor does not belong to this resource")
+ }
+ cur = &c
+ }
+ return limit, cur, nil
+}
+
+func writeJSON(w http.ResponseWriter, r *http.Request, status int, payload any) {
+ w.Header().Set("Content-Type", "application/json; charset=utf-8")
+ w.Header().Set("X-Request-Id", requestID(r))
+ w.WriteHeader(status)
+ _ = json.NewEncoder(w).Encode(payload)
+}
+
+func methodNotAllowed(w http.ResponseWriter, r *http.Request) {
+ apperr.Write(w, requestID(r), apperr.New(http.StatusMethodNotAllowed, apperr.CodeInvalidRequest, "method not allowed"))
+}
diff --git a/src/internal/api/middleware.go b/src/internal/api/middleware.go
new file mode 100644
index 00000000..e5732461
--- /dev/null
+++ b/src/internal/api/middleware.go
@@ -0,0 +1,145 @@
+package api
+
+import (
+ "context"
+ "errors"
+ "log/slog"
+ "net/http"
+ "strings"
+ "time"
+
+ "github.com/google/uuid"
+
+ "mtusi-messenger/internal/apperr"
+ "mtusi-messenger/internal/auth"
+ "mtusi-messenger/internal/model"
+)
+
+type ctxKey int
+
+const (
+ ctxRequestID ctxKey = iota
+ ctxUser
+ ctxToken
+)
+
+func requestIDMiddleware(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ id := r.Header.Get("X-Request-Id")
+ if id == "" {
+ id = uuid.NewString()
+ }
+ w.Header().Set("X-Request-Id", id)
+ next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), ctxRequestID, id)))
+ })
+}
+
+func instanceIDMiddleware(instanceID string, next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("X-Instance-Id", instanceID)
+ next.ServeHTTP(w, r)
+ })
+}
+
+func requestID(r *http.Request) string {
+ if id, ok := r.Context().Value(ctxRequestID).(string); ok && id != "" {
+ return id
+ }
+ return "unknown"
+}
+
+type statusWriter struct {
+ http.ResponseWriter
+ status int
+}
+
+func (s *statusWriter) WriteHeader(code int) {
+ s.status = code
+ s.ResponseWriter.WriteHeader(code)
+}
+
+func loggingMiddleware(log *slog.Logger, next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ start := time.Now()
+ sw := &statusWriter{ResponseWriter: w, status: http.StatusOK}
+ next.ServeHTTP(sw, r)
+
+ log.Info("http",
+ "method", r.Method,
+ "path", r.URL.Path,
+ "status", sw.status,
+ "dur_ms", time.Since(start).Milliseconds(),
+ "request_id", requestID(r),
+ )
+ })
+}
+
+func recoverMiddleware(log *slog.Logger, next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ defer func() {
+ if rec := recover(); rec != nil {
+ log.Error("panic recovered", "path", r.URL.Path, "request_id", requestID(r))
+ apperr.Write(w, requestID(r), apperr.Internal("internal error"))
+ }
+ }()
+ next.ServeHTTP(w, r)
+ })
+}
+
+func timeoutMiddleware(d time.Duration, next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ ctx, cancel := context.WithTimeout(r.Context(), d)
+ defer cancel()
+ next.ServeHTTP(w, r.WithContext(ctx))
+ })
+}
+
+const bearerChallenge = `Bearer realm="messenger"`
+
+func unauthorizedBearer(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("WWW-Authenticate", bearerChallenge)
+ apperr.Write(w, requestID(r), apperr.Unauthorized("valid Bearer session token is required"))
+}
+
+func bearerToken(r *http.Request) (string, bool) {
+ scheme, token, ok := strings.Cut(r.Header.Get("Authorization"), " ")
+ if !ok || !strings.EqualFold(scheme, "Bearer") {
+ return "", false
+ }
+ token = strings.TrimSpace(token)
+ if token == "" || len(token) > 256 {
+ return "", false
+ }
+ return token, true
+}
+
+func (s *Server) auth(next http.HandlerFunc) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ token, ok := bearerToken(r)
+ if !ok {
+ unauthorizedBearer(w, r)
+ return
+ }
+ user, err := s.sessions.Resolve(r.Context(), token)
+ if errors.Is(err, auth.ErrInvalidSession) {
+ unauthorizedBearer(w, r)
+ return
+ }
+ if err != nil {
+
+ s.storeError(w, r, err)
+ return
+ }
+ ctx := context.WithValue(r.Context(), ctxUser, user)
+ ctx = context.WithValue(ctx, ctxToken, token)
+ next.ServeHTTP(w, r.WithContext(ctx))
+ }
+}
+
+func currentUser(r *http.Request) *model.User {
+ return r.Context().Value(ctxUser).(*model.User)
+}
+
+func currentToken(r *http.Request) string {
+ return r.Context().Value(ctxToken).(string)
+}
diff --git a/src/internal/api/router.go b/src/internal/api/router.go
new file mode 100644
index 00000000..f4255c3d
--- /dev/null
+++ b/src/internal/api/router.go
@@ -0,0 +1,62 @@
+package api
+
+import (
+ "log/slog"
+ "net/http"
+ "sync/atomic"
+ "time"
+
+ "mtusi-messenger/internal/auth"
+ "mtusi-messenger/internal/store"
+)
+
+type Server struct {
+ store *store.Store
+ sessions *auth.Sessions
+ hasher *auth.Hasher
+ log *slog.Logger
+ ready *atomic.Bool
+ timeout time.Duration
+
+ instanceID string
+ idempotencyTTL time.Duration
+ writePath string
+}
+
+const (
+ WritePathOneShot = "oneshot"
+ WritePathTx = "tx"
+)
+
+type Options struct {
+ InstanceID string
+ IdempotencyTTL time.Duration
+ WritePath string
+}
+
+func NewServer(st *store.Store, sessions *auth.Sessions, hasher *auth.Hasher, log *slog.Logger, ready *atomic.Bool, opt Options) *Server {
+ return &Server{store: st, sessions: sessions, hasher: hasher, log: log, ready: ready, timeout: 8 * time.Second,
+ instanceID: opt.InstanceID, idempotencyTTL: opt.IdempotencyTTL, writePath: opt.WritePath}
+}
+
+func (s *Server) Handler() http.Handler {
+ mux := http.NewServeMux()
+ mux.HandleFunc("/health/live", s.healthLive)
+ mux.HandleFunc("/health/ready", s.healthReady)
+ mux.HandleFunc("/api/v1/users", s.usersRoute)
+ mux.HandleFunc("/api/v1/auth/sessions", s.createSession)
+ mux.HandleFunc("/api/v1/auth/sessions/current", s.auth(s.revokeSession))
+ mux.HandleFunc("/api/v1/users/me", s.auth(s.me))
+ mux.HandleFunc("/api/v1/chats", s.auth(s.chatsRoute))
+ mux.HandleFunc("/api/v1/chats/{chat_id}", s.auth(s.chatRoute))
+ mux.HandleFunc("/api/v1/chats/{chat_id}/messages", s.auth(s.messagesRoute))
+ mux.HandleFunc("/", s.notFound)
+
+ var h http.Handler = mux
+ h = timeoutMiddleware(s.timeout, h)
+ h = recoverMiddleware(s.log, h)
+ h = loggingMiddleware(s.log, h)
+ h = requestIDMiddleware(h)
+ h = instanceIDMiddleware(s.instanceID, h)
+ return h
+}
diff --git a/src/internal/apperr/errors.go b/src/internal/apperr/errors.go
new file mode 100644
index 00000000..0c6d7c5e
--- /dev/null
+++ b/src/internal/apperr/errors.go
@@ -0,0 +1,64 @@
+package apperr
+
+import (
+ "encoding/json"
+ "net/http"
+)
+
+type Code string
+
+const (
+ CodeInvalidRequest Code = "invalid_request"
+ CodeUnauthorized Code = "unauthorized"
+ CodeNotFound Code = "not_found"
+ CodeConflict Code = "conflict"
+ CodePayloadTooLarge Code = "payload_too_large"
+ CodeUnsupportedMedia Code = "unsupported_media_type"
+ CodeRateLimited Code = "rate_limited"
+ CodeUnavailable Code = "unavailable"
+ CodeInternal Code = "internal_error"
+)
+
+type Body struct {
+ Code Code `json:"code"`
+ Message string `json:"message"`
+ RequestID string `json:"request_id"`
+}
+
+type Envelope struct {
+ Error Body `json:"error"`
+}
+
+type AppError struct {
+ Status int
+ Code Code
+ Msg string
+}
+
+func (e *AppError) Error() string { return e.Msg }
+
+func New(status int, code Code, msg string) *AppError {
+ return &AppError{Status: status, Code: code, Msg: msg}
+}
+
+func InvalidRequest(msg string) *AppError { return New(http.StatusBadRequest, CodeInvalidRequest, msg) }
+func Unauthorized(msg string) *AppError { return New(http.StatusUnauthorized, CodeUnauthorized, msg) }
+func NotFound(msg string) *AppError { return New(http.StatusNotFound, CodeNotFound, msg) }
+func Conflict(msg string) *AppError { return New(http.StatusConflict, CodeConflict, msg) }
+func PayloadTooLarge(msg string) *AppError {
+ return New(http.StatusRequestEntityTooLarge, CodePayloadTooLarge, msg)
+}
+func UnsupportedMedia(msg string) *AppError {
+ return New(http.StatusUnsupportedMediaType, CodeUnsupportedMedia, msg)
+}
+func Unavailable(msg string) *AppError {
+ return New(http.StatusServiceUnavailable, CodeUnavailable, msg)
+}
+func Internal(msg string) *AppError { return New(http.StatusInternalServerError, CodeInternal, msg) }
+
+func Write(w http.ResponseWriter, requestID string, err *AppError) {
+ w.Header().Set("Content-Type", "application/json; charset=utf-8")
+ w.Header().Set("X-Request-Id", requestID)
+ w.WriteHeader(err.Status)
+ _ = json.NewEncoder(w).Encode(Envelope{Error: Body{Code: err.Code, Message: err.Msg, RequestID: requestID}})
+}
diff --git a/src/internal/auth/password.go b/src/internal/auth/password.go
new file mode 100644
index 00000000..ceaf8fe4
--- /dev/null
+++ b/src/internal/auth/password.go
@@ -0,0 +1,100 @@
+package auth
+
+import (
+ "context"
+ "crypto/rand"
+ "crypto/subtle"
+ "encoding/base64"
+ "errors"
+ "fmt"
+ "strings"
+
+ "golang.org/x/crypto/argon2"
+)
+
+const (
+ argonMemoryKiB = 19 * 1024
+ argonTime = 2
+ argonThreads = 1
+ argonKeyLen = 32
+ argonSaltLen = 16
+)
+
+var ErrBadHash = errors.New("malformed password hash")
+
+type Hasher struct {
+ slots chan struct{}
+ dummy string
+}
+
+func NewHasher(concurrency int) *Hasher {
+ h := &Hasher{slots: make(chan struct{}, concurrency)}
+
+ salt := make([]byte, argonSaltLen)
+ _, _ = rand.Read(salt)
+ h.dummy = encode(salt, argon2.IDKey([]byte("dummy-password-x"), salt, argonTime, argonMemoryKiB, argonThreads, argonKeyLen))
+ return h
+}
+
+func (h *Hasher) acquire(ctx context.Context) error {
+ select {
+ case h.slots <- struct{}{}:
+ return nil
+ case <-ctx.Done():
+ return ctx.Err()
+ }
+}
+
+func (h *Hasher) release() { <-h.slots }
+
+func encode(salt, key []byte) string {
+ return fmt.Sprintf("$argon2id$v=%d$m=%d,t=%d,p=%d$%s$%s", argon2.Version, argonMemoryKiB, argonTime, argonThreads,
+ base64.RawStdEncoding.EncodeToString(salt), base64.RawStdEncoding.EncodeToString(key))
+}
+
+func (h *Hasher) Hash(ctx context.Context, password string) (string, error) {
+ if err := h.acquire(ctx); err != nil {
+ return "", err
+ }
+ defer h.release()
+ salt := make([]byte, argonSaltLen)
+ if _, err := rand.Read(salt); err != nil {
+ return "", err
+ }
+ return encode(salt, argon2.IDKey([]byte(password), salt, argonTime, argonMemoryKiB, argonThreads, argonKeyLen)), nil
+}
+
+func (h *Hasher) Verify(ctx context.Context, password, encoded string) (bool, error) {
+ missing := encoded == ""
+ if missing {
+ encoded = h.dummy
+ }
+ parts := strings.Split(encoded, "$")
+ if len(parts) != 6 || parts[1] != "argon2id" {
+ return false, ErrBadHash
+ }
+ var version int
+ var mem uint32
+ var t uint32
+ var p uint8
+ if _, err := fmt.Sscanf(parts[2], "v=%d", &version); err != nil || version != argon2.Version {
+ return false, ErrBadHash
+ }
+ if _, err := fmt.Sscanf(parts[3], "m=%d,t=%d,p=%d", &mem, &t, &p); err != nil {
+ return false, ErrBadHash
+ }
+ salt, err := base64.RawStdEncoding.DecodeString(parts[4])
+ if err != nil {
+ return false, ErrBadHash
+ }
+ want, err := base64.RawStdEncoding.DecodeString(parts[5])
+ if err != nil {
+ return false, ErrBadHash
+ }
+ if err := h.acquire(ctx); err != nil {
+ return false, err
+ }
+ got := argon2.IDKey([]byte(password), salt, t, mem, p, uint32(len(want)))
+ h.release()
+ return subtle.ConstantTimeCompare(got, want) == 1 && !missing, nil
+}
diff --git a/src/internal/auth/sessions.go b/src/internal/auth/sessions.go
new file mode 100644
index 00000000..cf0a51ec
--- /dev/null
+++ b/src/internal/auth/sessions.go
@@ -0,0 +1,137 @@
+package auth
+
+import (
+ "context"
+ "crypto/rand"
+ "crypto/sha256"
+ "encoding/base64"
+ "errors"
+ "log/slog"
+ "time"
+
+ "mtusi-messenger/internal/model"
+ "mtusi-messenger/internal/store"
+)
+
+var (
+ ErrInvalidSession = errors.New("invalid session")
+ ErrCacheUnavailable = errors.New("session cache unavailable")
+)
+
+type SessionCache interface {
+ Get(ctx context.Context, key string) (*CachedSession, error)
+ Set(ctx context.Context, key string, s *CachedSession, ttl time.Duration) error
+ Del(ctx context.Context, key string) error
+}
+
+type CachedSession struct {
+ User model.User `json:"user"`
+ ExpiresAt time.Time `json:"exp"`
+}
+
+type Sessions struct {
+ store *store.Store
+ cache SessionCache
+ ttl time.Duration
+ cacheMaxTTL time.Duration
+ log *slog.Logger
+}
+
+func NewSessions(st *store.Store, cache SessionCache, ttl, cacheMaxTTL time.Duration, log *slog.Logger) *Sessions {
+ return &Sessions{store: st, cache: cache, ttl: ttl, cacheMaxTTL: cacheMaxTTL, log: log}
+}
+
+func NewToken() (string, []byte, error) {
+ raw := make([]byte, 32)
+ if _, err := rand.Read(raw); err != nil {
+ return "", nil, err
+ }
+ token := base64.RawURLEncoding.EncodeToString(raw)
+ return token, HashToken(token), nil
+}
+
+func HashToken(token string) []byte {
+ sum := sha256.Sum256([]byte(token))
+ return sum[:]
+}
+
+func cacheKey(hash []byte) string {
+ return "sess:" + base64.RawURLEncoding.EncodeToString(hash)
+}
+
+func (s *Sessions) Create(ctx context.Context, user *model.User) (string, time.Time, error) {
+ token, hash, err := NewToken()
+ if err != nil {
+ return "", time.Time{}, err
+ }
+ expires, err := s.store.CreateSession(ctx, hash, user.ID, s.ttl)
+ if err != nil {
+ return "", time.Time{}, err
+ }
+ s.cacheSet(ctx, hash, user, expires)
+ return token, expires, nil
+}
+
+func (s *Sessions) Resolve(ctx context.Context, token string) (*model.User, error) {
+ hash := HashToken(token)
+ if s.cache != nil {
+ cs, err := s.cache.Get(ctx, cacheKey(hash))
+ if err == nil && cs != nil {
+ if time.Now().Before(cs.ExpiresAt) {
+ u := cs.User
+ return &u, nil
+ }
+
+ } else if err != nil {
+ s.log.Debug("session cache get failed, falling back to postgres", "error", err.Error())
+ }
+ }
+ user, expires, err := s.store.SessionUser(ctx, hash)
+ if errors.Is(err, store.ErrNotFound) {
+ return nil, ErrInvalidSession
+ }
+ if err != nil {
+ return nil, err
+ }
+ s.cacheSet(ctx, hash, user, expires)
+ return user, nil
+}
+
+func (s *Sessions) Revoke(ctx context.Context, token string) error {
+ hash := HashToken(token)
+ if s.cache != nil {
+ if err := s.cache.Del(ctx, cacheKey(hash)); err != nil {
+ return ErrCacheUnavailable
+ }
+ }
+ err := s.store.RevokeSession(ctx, hash)
+ if errors.Is(err, store.ErrNotFound) {
+ return ErrInvalidSession
+ }
+ if err != nil {
+ return err
+ }
+ if s.cache != nil {
+ if err := s.cache.Del(ctx, cacheKey(hash)); err != nil {
+
+ s.log.Warn("session cache delete after revoke failed", "error", err.Error())
+ }
+ }
+ return nil
+}
+
+func (s *Sessions) cacheSet(ctx context.Context, hash []byte, user *model.User, expires time.Time) {
+ if s.cache == nil {
+ return
+ }
+ ttl := time.Until(expires)
+ if ttl > s.cacheMaxTTL {
+ ttl = s.cacheMaxTTL
+ }
+ if ttl <= 0 {
+ return
+ }
+ if err := s.cache.Set(ctx, cacheKey(hash), &CachedSession{User: *user, ExpiresAt: expires}, ttl); err != nil {
+ s.log.Debug("session cache set failed", "error", err.Error())
+ }
+}
diff --git a/src/internal/cache/valkey.go b/src/internal/cache/valkey.go
new file mode 100644
index 00000000..591d9e49
--- /dev/null
+++ b/src/internal/cache/valkey.go
@@ -0,0 +1,80 @@
+package cache
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "sync/atomic"
+ "time"
+
+ "github.com/redis/go-redis/v9"
+
+ "mtusi-messenger/internal/auth"
+)
+
+var ErrOpen = errors.New("cache circuit open")
+
+type Valkey struct {
+ rdb *redis.Client
+ openUntil atomic.Int64
+ cooldown time.Duration
+}
+
+func NewValkey(url string) (*Valkey, error) {
+ opt, err := redis.ParseURL(url)
+ if err != nil {
+ return nil, err
+ }
+ opt.DialTimeout = 500 * time.Millisecond
+ opt.ReadTimeout = 300 * time.Millisecond
+ opt.WriteTimeout = 300 * time.Millisecond
+ opt.PoolSize = 10
+ opt.MaxRetries = 0
+ return &Valkey{rdb: redis.NewClient(opt), cooldown: 2 * time.Second}, nil
+}
+
+func (v *Valkey) Close() error { return v.rdb.Close() }
+
+func (v *Valkey) Ping(ctx context.Context) error { return v.guard(v.rdb.Ping(ctx).Err()) }
+
+func (v *Valkey) open() bool { return time.Now().UnixNano() < v.openUntil.Load() }
+
+func (v *Valkey) guard(err error) error {
+ if err != nil && !errors.Is(err, redis.Nil) {
+ v.openUntil.Store(time.Now().Add(v.cooldown).UnixNano())
+ }
+ return err
+}
+
+func (v *Valkey) Get(ctx context.Context, key string) (*auth.CachedSession, error) {
+ if v.open() {
+ return nil, ErrOpen
+ }
+ raw, err := v.rdb.Get(ctx, key).Bytes()
+ if errors.Is(err, redis.Nil) {
+ return nil, nil
+ }
+ if err := v.guard(err); err != nil {
+ return nil, err
+ }
+ var cs auth.CachedSession
+ if err := json.Unmarshal(raw, &cs); err != nil {
+ return nil, nil
+ }
+ return &cs, nil
+}
+
+func (v *Valkey) Set(ctx context.Context, key string, s *auth.CachedSession, ttl time.Duration) error {
+ if v.open() {
+ return ErrOpen
+ }
+ raw, err := json.Marshal(s)
+ if err != nil {
+ return err
+ }
+ return v.guard(v.rdb.Set(ctx, key, raw, ttl).Err())
+}
+
+func (v *Valkey) Del(ctx context.Context, key string) error {
+ return v.guard(v.rdb.Del(ctx, key).Err())
+}
diff --git a/src/internal/db/migrate.go b/src/internal/db/migrate.go
new file mode 100644
index 00000000..96d0c779
--- /dev/null
+++ b/src/internal/db/migrate.go
@@ -0,0 +1,122 @@
+package db
+
+import (
+ "context"
+ "embed"
+ "fmt"
+ "io/fs"
+ "log/slog"
+ "sort"
+ "strconv"
+ "strings"
+
+ "github.com/jackc/pgx/v5/pgxpool"
+)
+
+//go:embed migrations/*.sql
+var migrationFS embed.FS
+
+const advisoryLockID = 20260202
+
+type migration struct {
+ version int
+ name string
+ sql string
+}
+
+func loadMigrations() ([]migration, error) {
+ entries, err := fs.ReadDir(migrationFS, "migrations")
+ if err != nil {
+ return nil, err
+ }
+ var out []migration
+ for _, e := range entries {
+ name := e.Name()
+ prefix, _, ok := strings.Cut(name, "_")
+ if !ok || !strings.HasSuffix(name, ".sql") {
+ return nil, fmt.Errorf("bad migration file name %q", name)
+ }
+ v, err := strconv.Atoi(prefix)
+ if err != nil {
+ return nil, fmt.Errorf("bad migration version in %q", name)
+ }
+ body, err := migrationFS.ReadFile("migrations/" + name)
+ if err != nil {
+ return nil, err
+ }
+ out = append(out, migration{version: v, name: name, sql: string(body)})
+ }
+ sort.Slice(out, func(i, j int) bool { return out[i].version < out[j].version })
+ for i := 1; i < len(out); i++ {
+ if out[i].version == out[i-1].version {
+ return nil, fmt.Errorf("duplicate migration version %d", out[i].version)
+ }
+ }
+ return out, nil
+}
+
+func Migrate(ctx context.Context, pool *pgxpool.Pool, log *slog.Logger) error {
+ migs, err := loadMigrations()
+ if err != nil {
+ return err
+ }
+ conn, err := pool.Acquire(ctx)
+ if err != nil {
+ return err
+ }
+ defer conn.Release()
+
+ if _, err := conn.Exec(ctx, "SELECT pg_advisory_lock($1)", advisoryLockID); err != nil {
+ return err
+ }
+ defer conn.Exec(context.Background(), "SELECT pg_advisory_unlock($1)", advisoryLockID)
+
+ if _, err := conn.Exec(ctx, `CREATE TABLE IF NOT EXISTS schema_migrations (
+ version integer PRIMARY KEY,
+ name text NOT NULL,
+ applied_at timestamptz NOT NULL DEFAULT now())`); err != nil {
+ return err
+ }
+
+ applied := map[int]bool{}
+ rows, err := conn.Query(ctx, "SELECT version FROM schema_migrations")
+ if err != nil {
+ return err
+ }
+ for rows.Next() {
+ var v int
+ if err := rows.Scan(&v); err != nil {
+ rows.Close()
+ return err
+ }
+ applied[v] = true
+ }
+ rows.Close()
+ if err := rows.Err(); err != nil {
+ return err
+ }
+
+ for _, m := range migs {
+ if applied[m.version] {
+ continue
+ }
+ tx, err := conn.Begin(ctx)
+ if err != nil {
+ return err
+ }
+ if _, err := tx.Exec(ctx, m.sql); err != nil {
+ _ = tx.Rollback(ctx)
+ return fmt.Errorf("migration %s: %w", m.name, err)
+ }
+ if _, err := tx.Exec(ctx, "INSERT INTO schema_migrations (version, name) VALUES ($1, $2)", m.version, m.name); err != nil {
+ _ = tx.Rollback(ctx)
+ return err
+ }
+ if err := tx.Commit(ctx); err != nil {
+ return err
+ }
+ log.Info("migration applied", "version", m.version, "name", m.name)
+ }
+ log.Info("migrations up to date", "total", len(migs))
+ return nil
+}
diff --git a/src/internal/db/migrations/0001_init.sql b/src/internal/db/migrations/0001_init.sql
new file mode 100644
index 00000000..a500b303
--- /dev/null
+++ b/src/internal/db/migrations/0001_init.sql
@@ -0,0 +1,51 @@
+CREATE TABLE users (
+ id uuid PRIMARY KEY,
+ username text NOT NULL,
+ display_name text NOT NULL,
+ password_hash text NOT NULL,
+ created_at timestamptz NOT NULL DEFAULT date_trunc('milliseconds', now()),
+ CONSTRAINT users_username_key UNIQUE (username),
+ CONSTRAINT users_username_format CHECK (username ~ '^[a-z0-9_]{3,32}$'),
+ CONSTRAINT users_display_name_len CHECK (char_length(display_name) BETWEEN 1 AND 100)
+);
+
+CREATE TABLE chats (
+ id uuid PRIMARY KEY,
+ title text NOT NULL,
+ created_by uuid NOT NULL REFERENCES users (id),
+ created_at timestamptz NOT NULL DEFAULT date_trunc('milliseconds', now()),
+ CONSTRAINT chats_title_len CHECK (char_length(title) BETWEEN 1 AND 100)
+);
+
+CREATE TABLE chat_members (
+ chat_id uuid NOT NULL REFERENCES chats (id) ON DELETE CASCADE,
+ user_id uuid NOT NULL REFERENCES users (id),
+ position smallint NOT NULL,
+ PRIMARY KEY (chat_id, user_id),
+ CONSTRAINT chat_members_position_key UNIQUE (chat_id, position)
+);
+CREATE INDEX chat_members_user_idx ON chat_members (user_id, chat_id);
+
+CREATE TABLE messages (
+ id uuid PRIMARY KEY,
+ chat_id uuid NOT NULL,
+ sender_id uuid NOT NULL,
+ text text NOT NULL,
+ created_at timestamptz NOT NULL DEFAULT date_trunc('milliseconds', now()),
+ CONSTRAINT messages_text_len CHECK (char_length(text) BETWEEN 1 AND 4000),
+ CONSTRAINT messages_sender_member_fk FOREIGN KEY (chat_id, sender_id)
+ REFERENCES chat_members (chat_id, user_id) ON DELETE CASCADE
+);
+CREATE INDEX messages_chat_history_idx ON messages (chat_id, created_at, id);
+
+CREATE TABLE sessions (
+ token_hash bytea PRIMARY KEY,
+ user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
+ created_at timestamptz NOT NULL DEFAULT date_trunc('milliseconds', now()),
+ expires_at timestamptz NOT NULL,
+ revoked_at timestamptz,
+ CONSTRAINT sessions_token_hash_len CHECK (octet_length(token_hash) = 32),
+ CONSTRAINT sessions_expiry_after_create CHECK (expires_at > created_at)
+);
+CREATE INDEX sessions_user_idx ON sessions (user_id);
+CREATE INDEX sessions_expires_idx ON sessions (expires_at);
diff --git a/src/internal/db/migrations/0002_message_idempotency.sql b/src/internal/db/migrations/0002_message_idempotency.sql
new file mode 100644
index 00000000..5103b78d
--- /dev/null
+++ b/src/internal/db/migrations/0002_message_idempotency.sql
@@ -0,0 +1,13 @@
+CREATE TABLE message_idempotency (
+ user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
+ chat_id uuid NOT NULL REFERENCES chats (id) ON DELETE CASCADE,
+ idem_key text NOT NULL,
+ request_hash bytea NOT NULL,
+ message_id uuid NOT NULL REFERENCES messages (id) ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ created_at timestamptz NOT NULL DEFAULT now(),
+ PRIMARY KEY (user_id, chat_id, idem_key),
+ CONSTRAINT message_idempotency_key_format CHECK (idem_key ~ '^[A-Za-z0-9._:-]{1,128}$'),
+ CONSTRAINT message_idempotency_hash_len CHECK (octet_length(request_hash) = 32)
+);
+CREATE INDEX message_idempotency_created_idx ON message_idempotency (created_at);
diff --git a/src/internal/db/pool.go b/src/internal/db/pool.go
new file mode 100644
index 00000000..3c818a19
--- /dev/null
+++ b/src/internal/db/pool.go
@@ -0,0 +1,31 @@
+package db
+
+import (
+ "context"
+ "time"
+
+ "github.com/jackc/pgx/v5/pgxpool"
+)
+
+type PoolOptions struct {
+ MaxConns int32
+}
+
+func Open(ctx context.Context, url string, opt PoolOptions) (*pgxpool.Pool, error) {
+ cfg, err := pgxpool.ParseConfig(url)
+ if err != nil {
+ return nil, err
+ }
+ cfg.MaxConns = opt.MaxConns
+ cfg.MinConns = 1
+ cfg.MaxConnLifetime = 30 * time.Minute
+ cfg.MaxConnIdleTime = 5 * time.Minute
+ cfg.HealthCheckPeriod = 15 * time.Second
+ cfg.ConnConfig.ConnectTimeout = 3 * time.Second
+ rp := cfg.ConnConfig.RuntimeParams
+ rp["application_name"] = "mtusi-messenger"
+ rp["statement_timeout"] = "5000"
+ rp["lock_timeout"] = "2000"
+ rp["idle_in_transaction_session_timeout"] = "10000"
+ return pgxpool.NewWithConfig(ctx, cfg)
+}
diff --git a/src/internal/model/models.go b/src/internal/model/models.go
new file mode 100644
index 00000000..33a8da13
--- /dev/null
+++ b/src/internal/model/models.go
@@ -0,0 +1,51 @@
+package model
+
+import "time"
+
+type Time struct {
+ time.Time
+}
+
+func NewTime(t time.Time) Time { return Time{Time: t} }
+
+func (t Time) MarshalJSON() ([]byte, error) {
+ return []byte(`"` + t.UTC().Format("2006-01-02T15:04:05.000Z") + `"`), nil
+}
+
+type User struct {
+ ID string `json:"id"`
+ Username string `json:"username"`
+ DisplayName string `json:"display_name"`
+ CreatedAt Time `json:"created_at"`
+}
+
+type Chat struct {
+ ID string `json:"id"`
+ Title string `json:"title"`
+ MemberIDs []string `json:"member_ids"`
+ CreatedAt Time `json:"created_at"`
+}
+
+type Message struct {
+ ID string `json:"id"`
+ ChatID string `json:"chat_id"`
+ SenderID string `json:"sender_id"`
+ Text string `json:"text"`
+ CreatedAt Time `json:"created_at"`
+}
+
+type Page[T any] struct {
+ Items []T `json:"items"`
+ NextCursor *string `json:"next_cursor"`
+}
+
+type Health struct {
+ Status string `json:"status"`
+}
+
+type Session struct {
+ Token string `json:"token"`
+ TokenType string `json:"token_type"`
+ ExpiresAt Time `json:"expires_at"`
+ User User `json:"user"`
+}
diff --git a/src/internal/store/cursor.go b/src/internal/store/cursor.go
new file mode 100644
index 00000000..209405b2
--- /dev/null
+++ b/src/internal/store/cursor.go
@@ -0,0 +1,33 @@
+package store
+
+import (
+ "encoding/base64"
+ "encoding/json"
+ "time"
+)
+
+type Cursor struct {
+ Scope string `json:"s"`
+ TS time.Time `json:"t"`
+ ID string `json:"i"`
+}
+
+func EncodeCursor(c Cursor) string {
+ b, _ := json.Marshal(c)
+ return base64.RawURLEncoding.EncodeToString(b)
+}
+
+func DecodeCursor(s string) (Cursor, error) {
+ var c Cursor
+ b, err := base64.RawURLEncoding.DecodeString(s)
+ if err != nil {
+ return c, ErrInvalidCursor
+ }
+ if err := json.Unmarshal(b, &c); err != nil {
+ return c, ErrInvalidCursor
+ }
+ if c.Scope == "" || c.ID == "" || c.TS.IsZero() {
+ return c, ErrInvalidCursor
+ }
+ return c, nil
+}
diff --git a/src/internal/store/postgres.go b/src/internal/store/postgres.go
new file mode 100644
index 00000000..a9d0eced
--- /dev/null
+++ b/src/internal/store/postgres.go
@@ -0,0 +1,416 @@
+package store
+
+import (
+ "bytes"
+ "context"
+ "errors"
+ "net"
+ "time"
+
+ "github.com/google/uuid"
+ "github.com/jackc/pgx/v5"
+ "github.com/jackc/pgx/v5/pgconn"
+ "github.com/jackc/pgx/v5/pgxpool"
+
+ "mtusi-messenger/internal/model"
+)
+
+var (
+ ErrNotFound = errors.New("not found")
+ ErrUsernameTaken = errors.New("username taken")
+ ErrUnknownMember = errors.New("unknown member")
+ ErrInvalidCursor = errors.New("invalid cursor")
+)
+
+type Store struct {
+ pool *pgxpool.Pool
+}
+
+func New(pool *pgxpool.Pool) *Store { return &Store{pool: pool} }
+
+func (s *Store) Ping(ctx context.Context) error { return s.pool.Ping(ctx) }
+
+func IsUnavailable(err error) bool {
+ if err == nil {
+ return false
+ }
+ if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) || pgconn.Timeout(err) {
+ return true
+ }
+ var connErr *pgconn.ConnectError
+ if errors.As(err, &connErr) {
+ return true
+ }
+ var netErr net.Error
+ if errors.As(err, &netErr) {
+ return true
+ }
+ var pgErr *pgconn.PgError
+ if errors.As(err, &pgErr) {
+
+ switch {
+ case pgErr.Code == "57P01", pgErr.Code == "57P03", pgErr.Code == "57014", pgErr.Code == "55P03",
+ len(pgErr.Code) == 5 && pgErr.Code[:2] == "08":
+ return true
+ }
+ }
+ return errors.Is(err, pgx.ErrTxClosed) || errors.Is(err, net.ErrClosed)
+}
+
+func pgCode(err error) string {
+ var pgErr *pgconn.PgError
+ if errors.As(err, &pgErr) {
+ return pgErr.Code
+ }
+ return ""
+}
+
+func utc(t time.Time) model.Time { return model.NewTime(t.UTC()) }
+
+func (s *Store) CreateUser(ctx context.Context, username, displayName, passwordHash string) (*model.User, error) {
+ u := &model.User{ID: uuid.NewString(), Username: username, DisplayName: displayName}
+ var created time.Time
+ err := s.pool.QueryRow(ctx,
+ `INSERT INTO users (id, username, display_name, password_hash)
+ VALUES ($1, $2, $3, $4) RETURNING created_at`,
+ u.ID, username, displayName, passwordHash).Scan(&created)
+ if pgCode(err) == "23505" {
+ return nil, ErrUsernameTaken
+ }
+ if err != nil {
+ return nil, err
+ }
+ u.CreatedAt = utc(created)
+ return u, nil
+}
+
+func (s *Store) Credentials(ctx context.Context, username string) (*model.User, string, error) {
+ u := &model.User{}
+ var created time.Time
+ var hash string
+ err := s.pool.QueryRow(ctx,
+ `SELECT id, username, display_name, created_at, password_hash FROM users WHERE username = $1`,
+ username).Scan(&u.ID, &u.Username, &u.DisplayName, &created, &hash)
+ if errors.Is(err, pgx.ErrNoRows) {
+ return nil, "", ErrNotFound
+ }
+ if err != nil {
+ return nil, "", err
+ }
+ u.CreatedAt = utc(created)
+ return u, hash, nil
+}
+
+func (s *Store) CreateSession(ctx context.Context, tokenHash []byte, userID string, ttl time.Duration) (time.Time, error) {
+ var expires time.Time
+ err := s.pool.QueryRow(ctx,
+ `INSERT INTO sessions (token_hash, user_id, expires_at)
+ VALUES ($1, $2, date_trunc('milliseconds', now()) + make_interval(secs => $3))
+ RETURNING expires_at`,
+ tokenHash, userID, ttl.Seconds()).Scan(&expires)
+ if err != nil {
+ return time.Time{}, err
+ }
+ return expires.UTC(), nil
+}
+
+func (s *Store) SessionUser(ctx context.Context, tokenHash []byte) (*model.User, time.Time, error) {
+ u := &model.User{}
+ var created, expires time.Time
+ err := s.pool.QueryRow(ctx,
+ `SELECT u.id, u.username, u.display_name, u.created_at, s.expires_at
+ FROM sessions s JOIN users u ON u.id = s.user_id
+ WHERE s.token_hash = $1 AND s.revoked_at IS NULL AND s.expires_at > now()`,
+ tokenHash).Scan(&u.ID, &u.Username, &u.DisplayName, &created, &expires)
+ if errors.Is(err, pgx.ErrNoRows) {
+ return nil, time.Time{}, ErrNotFound
+ }
+ if err != nil {
+ return nil, time.Time{}, err
+ }
+ u.CreatedAt = utc(created)
+ return u, expires.UTC(), nil
+}
+
+func (s *Store) RevokeSession(ctx context.Context, tokenHash []byte) error {
+ tag, err := s.pool.Exec(ctx,
+ `UPDATE sessions SET revoked_at = now()
+ WHERE token_hash = $1 AND revoked_at IS NULL AND expires_at > now()`, tokenHash)
+ if err != nil {
+ return err
+ }
+ if tag.RowsAffected() == 0 {
+ return ErrNotFound
+ }
+ return nil
+}
+
+func (s *Store) PurgeSessions(ctx context.Context, olderThan time.Duration) (int64, error) {
+ tag, err := s.pool.Exec(ctx,
+ `DELETE FROM sessions
+ WHERE expires_at < now() - make_interval(secs => $1)
+ OR revoked_at < now() - make_interval(secs => $1)`, olderThan.Seconds())
+ if err != nil {
+ return 0, err
+ }
+ return tag.RowsAffected(), nil
+}
+
+func (s *Store) CreateChat(ctx context.Context, creatorID, title string, memberIDs []string) (*model.Chat, error) {
+ c := &model.Chat{ID: uuid.NewString(), Title: title, MemberIDs: append([]string(nil), memberIDs...)}
+ err := pgx.BeginFunc(ctx, s.pool, func(tx pgx.Tx) error {
+ var created time.Time
+ if err := tx.QueryRow(ctx,
+ `INSERT INTO chats (id, title, created_by) VALUES ($1, $2, $3) RETURNING created_at`,
+ c.ID, title, creatorID).Scan(&created); err != nil {
+ return err
+ }
+ c.CreatedAt = utc(created)
+ _, err := tx.Exec(ctx,
+ `INSERT INTO chat_members (chat_id, user_id, position)
+ SELECT $1, m.user_id, m.ord - 1
+ FROM unnest($2::uuid[]) WITH ORDINALITY AS m(user_id, ord)`,
+ c.ID, memberIDs)
+ return err
+ })
+ if pgCode(err) == "23503" {
+ return nil, ErrUnknownMember
+ }
+ if err != nil {
+ return nil, err
+ }
+ return c, nil
+}
+
+func (s *Store) IsMember(ctx context.Context, chatID, userID string) (bool, error) {
+ var ok bool
+ err := s.pool.QueryRow(ctx,
+ `SELECT EXISTS (SELECT 1 FROM chat_members WHERE chat_id = $1 AND user_id = $2)`,
+ chatID, userID).Scan(&ok)
+ return ok, err
+}
+
+func (s *Store) ChatForUser(ctx context.Context, chatID, userID string) (*model.Chat, error) {
+ c := &model.Chat{}
+ var created time.Time
+ err := s.pool.QueryRow(ctx,
+ `SELECT c.id, c.title, c.created_at,
+ array_agg(m.user_id::text ORDER BY m.position)
+ FROM chats c JOIN chat_members m ON m.chat_id = c.id
+ WHERE c.id = $1
+ AND EXISTS (SELECT 1 FROM chat_members x WHERE x.chat_id = c.id AND x.user_id = $2)
+ GROUP BY c.id`,
+ chatID, userID).Scan(&c.ID, &c.Title, &created, &c.MemberIDs)
+ if errors.Is(err, pgx.ErrNoRows) {
+ return nil, ErrNotFound
+ }
+ if err != nil {
+ return nil, err
+ }
+ c.CreatedAt = utc(created)
+ return c, nil
+}
+
+func (s *Store) ListChats(ctx context.Context, userID string, limit int, cur *Cursor) ([]*model.Chat, bool, error) {
+ var ts *time.Time
+ var cid *string
+ if cur != nil {
+ ts, cid = &cur.TS, &cur.ID
+ }
+ rows, err := s.pool.Query(ctx,
+ `SELECT c.id, c.title, c.created_at,
+ (SELECT array_agg(m.user_id::text ORDER BY m.position) FROM chat_members m WHERE m.chat_id = c.id)
+ FROM chat_members me JOIN chats c ON c.id = me.chat_id
+ WHERE me.user_id = $1
+ AND ($2::timestamptz IS NULL OR (c.created_at, c.id) > ($2, $3::uuid))
+ ORDER BY c.created_at, c.id
+ LIMIT $4`,
+ userID, ts, cid, limit+1)
+ if err != nil {
+ return nil, false, err
+ }
+ defer rows.Close()
+ out := make([]*model.Chat, 0, limit+1)
+ for rows.Next() {
+ c := &model.Chat{}
+ var created time.Time
+ if err := rows.Scan(&c.ID, &c.Title, &created, &c.MemberIDs); err != nil {
+ return nil, false, err
+ }
+ c.CreatedAt = utc(created)
+ out = append(out, c)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, false, err
+ }
+ more := len(out) > limit
+ if more {
+ out = out[:limit]
+ }
+ return out, more, nil
+}
+
+var ErrIdempotencyConflict = errors.New("idempotency key reused with different body")
+
+func (s *Store) AddMessageIdempotent(ctx context.Context, chatID, senderID, text, key string, reqHash []byte, ttl time.Duration) (*model.Message, bool, error) {
+ tx, err := s.pool.Begin(ctx)
+ if err != nil {
+ return nil, false, err
+ }
+ defer tx.Rollback(context.Background())
+
+ newID := uuid.NewString()
+ var owned string
+ err = tx.QueryRow(ctx, `
+ INSERT INTO message_idempotency (user_id, chat_id, idem_key, request_hash, message_id)
+ VALUES ($1, $2, $3, $4, $5)
+ ON CONFLICT (user_id, chat_id, idem_key) DO UPDATE
+ SET request_hash = EXCLUDED.request_hash, message_id = EXCLUDED.message_id, created_at = now()
+ WHERE message_idempotency.created_at < now() - make_interval(secs => $6)
+ RETURNING message_id`,
+ senderID, chatID, key, reqHash, newID, ttl.Seconds()).Scan(&owned)
+ switch {
+ case errors.Is(err, pgx.ErrNoRows):
+ var stored []byte
+ m := &model.Message{ChatID: chatID}
+ var created time.Time
+ err = tx.QueryRow(ctx, `
+ SELECT i.request_hash, m.id, m.sender_id, m.text, m.created_at
+ FROM message_idempotency i JOIN messages m ON m.id = i.message_id
+ WHERE i.user_id = $1 AND i.chat_id = $2 AND i.idem_key = $3`,
+ senderID, chatID, key).Scan(&stored, &m.ID, &m.SenderID, &m.Text, &created)
+ if err != nil {
+ return nil, false, err
+ }
+ if !bytes.Equal(stored, reqHash) {
+ return nil, false, ErrIdempotencyConflict
+ }
+ m.CreatedAt = utc(created)
+ return m, true, nil
+ case pgCode(err) == "23503":
+ return nil, false, ErrNotFound
+ case err != nil:
+ return nil, false, err
+ }
+
+ m := &model.Message{ID: newID, ChatID: chatID, SenderID: senderID, Text: text}
+ var created time.Time
+ err = tx.QueryRow(ctx,
+ `INSERT INTO messages (id, chat_id, sender_id, text) VALUES ($1, $2, $3, $4) RETURNING created_at`,
+ newID, chatID, senderID, text).Scan(&created)
+ if pgCode(err) == "23503" {
+ return nil, false, ErrNotFound
+ }
+ if err != nil {
+ return nil, false, err
+ }
+ if err := tx.Commit(ctx); err != nil {
+ return nil, false, err
+ }
+ m.CreatedAt = utc(created)
+ return m, false, nil
+}
+
+func (s *Store) AddMessageOneShot(ctx context.Context, chatID, senderID, text, key string, reqHash []byte, ttl time.Duration) (*model.Message, bool, error) {
+ for attempt := 0; attempt < 2; attempt++ {
+ newID := uuid.NewString()
+ var member bool
+ var created *time.Time
+ err := s.pool.QueryRow(ctx, `
+ WITH member AS (
+ SELECT 1 FROM chat_members WHERE chat_id = $2 AND user_id = $1
+ ), k AS (
+ INSERT INTO message_idempotency (user_id, chat_id, idem_key, request_hash, message_id)
+ SELECT $1, $2, $3, $4, $5 FROM member
+ ON CONFLICT (user_id, chat_id, idem_key) DO UPDATE
+ SET request_hash = EXCLUDED.request_hash, message_id = EXCLUDED.message_id, created_at = now()
+ WHERE message_idempotency.created_at < now() - make_interval(secs => $7)
+ RETURNING message_id
+ ), m AS (
+ INSERT INTO messages (id, chat_id, sender_id, text)
+ SELECT $5, $2, $1, $6 FROM k
+ RETURNING created_at
+ )
+ SELECT EXISTS (SELECT 1 FROM member), (SELECT created_at FROM m)`,
+ senderID, chatID, key, reqHash, newID, text, ttl.Seconds()).Scan(&member, &created)
+ if err != nil {
+ return nil, false, err
+ }
+ if !member {
+ return nil, false, ErrNotFound
+ }
+ if created != nil {
+ return &model.Message{ID: newID, ChatID: chatID, SenderID: senderID, Text: text, CreatedAt: utc(*created)}, false, nil
+ }
+ var stored []byte
+ var at time.Time
+ m := &model.Message{ChatID: chatID}
+ err = s.pool.QueryRow(ctx, `
+ SELECT i.request_hash, m.id, m.sender_id, m.text, m.created_at
+ FROM message_idempotency i JOIN messages m ON m.id = i.message_id
+ WHERE i.user_id = $1 AND i.chat_id = $2 AND i.idem_key = $3
+ AND i.created_at >= now() - make_interval(secs => $4)`,
+ senderID, chatID, key, ttl.Seconds()).Scan(&stored, &m.ID, &m.SenderID, &m.Text, &at)
+ if errors.Is(err, pgx.ErrNoRows) {
+ continue
+ }
+ if err != nil {
+ return nil, false, err
+ }
+ if !bytes.Equal(stored, reqHash) {
+ return nil, false, ErrIdempotencyConflict
+ }
+ m.CreatedAt = utc(at)
+ return m, true, nil
+ }
+ return nil, false, errors.New("idempotency record kept changing")
+}
+
+func (s *Store) PurgeIdempotency(ctx context.Context, ttl time.Duration) (int64, error) {
+ tag, err := s.pool.Exec(ctx,
+ `DELETE FROM message_idempotency WHERE created_at < now() - make_interval(secs => $1)`, ttl.Seconds())
+ if err != nil {
+ return 0, err
+ }
+ return tag.RowsAffected(), nil
+}
+
+func (s *Store) ListMessages(ctx context.Context, chatID string, limit int, cur *Cursor) ([]*model.Message, bool, error) {
+ var (
+ rows pgx.Rows
+ err error
+ )
+ if cur == nil {
+ rows, err = s.pool.Query(ctx,
+ `SELECT id, chat_id, sender_id, text, created_at FROM messages
+ WHERE chat_id = $1
+ ORDER BY created_at, id LIMIT $2`, chatID, limit+1)
+ } else {
+ rows, err = s.pool.Query(ctx,
+ `SELECT id, chat_id, sender_id, text, created_at FROM messages
+ WHERE chat_id = $1 AND (created_at, id) > ($2, $3::uuid)
+ ORDER BY created_at, id LIMIT $4`, chatID, cur.TS, cur.ID, limit+1)
+ }
+ if err != nil {
+ return nil, false, err
+ }
+ defer rows.Close()
+ out := make([]*model.Message, 0, limit+1)
+ for rows.Next() {
+ m := &model.Message{}
+ var created time.Time
+ if err := rows.Scan(&m.ID, &m.ChatID, &m.SenderID, &m.Text, &created); err != nil {
+ return nil, false, err
+ }
+ m.CreatedAt = utc(created)
+ out = append(out, m)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, false, err
+ }
+ more := len(out) > limit
+ if more {
+ out = out[:limit]
+ }
+ return out, more, nil
+}
diff --git a/student-tests/run_tests.py b/student-tests/run_tests.py
new file mode 100644
index 00000000..4031053b
--- /dev/null
+++ b/student-tests/run_tests.py
@@ -0,0 +1,170 @@
+#!/usr/bin/env python3
+from concurrent.futures import ThreadPoolExecutor
+import json
+from pathlib import Path
+import sys
+import threading
+import uuid
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests'))
+from client import Client, Failure, check
+
+RESULTS = []
+
+
+def case(name):
+ def wrap(fn):
+ def run(*a):
+ try:
+ detail = fn(*a)
+ RESULTS.append({'test': name, 'result': 'PASS', 'detail': detail})
+ print('PASS', name, '-', detail or '')
+ except Failure as exc:
+ RESULTS.append({'test': name, 'result': 'FAIL', 'detail': str(exc)})
+ print('FAIL', name, '-', exc)
+ return run
+ return wrap
+
+
+def msg_path(chat):
+ return '/api/v1/chats/' + chat['id'] + '/messages'
+
+
+def history(c, actor, chat):
+ out, cursor = [], None
+ while True:
+ q = '?limit=100' + ('&cursor=' + cursor if cursor else '')
+ page = c.call('GET', msg_path(chat) + q, actor=actor, schema='MessagePage')['json']
+ out += page['items']
+ cursor = page['next_cursor']
+ if not cursor:
+ return out
+
+
+@case('one session served by >=2 replicas without re-login (no stickiness)')
+def t_no_sticky(c, alice, bob, chat):
+ seen = {}
+ for _ in range(30):
+ iid = c.call('GET', '/api/v1/users/me', actor=alice, schema='User')['headers']['X-Instance-Id']
+ seen[iid] = seen.get(iid, 0) + 1
+ check(len(seen) >= 2, 'only one replica observed: %s' % seen)
+ return 'distribution %s' % sorted(seen.values())
+
+
+@case('X-Instance-Id is present on errors and health too')
+def t_instance_on_errors(c, alice, bob, chat):
+ r = c.call('GET', '/api/v1/chats/not-a-uuid', 400, actor=alice)
+ check(bool(r['headers'].get('X-Instance-Id')), 'missing on 400')
+ r = c.call('GET', '/api/v1/users/me', 401)
+ check(bool(r['headers'].get('X-Instance-Id')), 'missing on 401')
+ r = c.call('GET', '/health/ready', schema='Health')
+ check(bool(r['headers'].get('X-Instance-Id')), 'missing on health')
+
+
+@case('Idempotency-Key missing or malformed -> 400, nothing stored')
+def t_key_validation(c, alice, bob, chat):
+ before = len(history(c, alice, chat))
+ c.call('POST', msg_path(chat), 400, actor=alice, body={'text': 'без ключа'})
+ for bad in ('', 'a b', 'clé', 'x' * 129, 'a/b'):
+ c.call('POST', msg_path(chat), 400, actor=alice, body={'text': 'плохой ключ'},
+ headers={'Idempotency-Key': bad})
+ c.call('POST', msg_path(chat), 201, actor=alice, body={'text': 'граница ключа'},
+ headers={'Idempotency-Key': 'A-z0_9.:' + 'k' * 120})
+ check(len(history(c, alice, chat)) == before + 1, 'rejected requests created messages')
+
+
+@case('concurrent replay of one key through different replicas -> exactly one message')
+def t_concurrent_same_key(c, alice, bob, chat):
+ key = 'conc-' + uuid.uuid4().hex
+ text = 'Конкурентный повтор ' + key
+ n = 24
+ barrier = threading.Barrier(n)
+ raw = json.dumps({'text': text}, ensure_ascii=False).encode()
+
+ def send(_):
+ local = Client(c.base, timeout=10)
+ barrier.wait()
+ r = local.call('POST', msg_path(chat), 201, actor=alice, raw=raw,
+ headers={'Idempotency-Key': key, 'Content-Type': 'application/json'}, schema='Message')
+ return r['json'], r['headers']['X-Instance-Id']
+
+ with ThreadPoolExecutor(max_workers=n) as pool:
+ results = list(pool.map(send, range(n)))
+ bodies = {json.dumps(m, sort_keys=True) for m, _ in results}
+ instances = {i for _, i in results}
+ check(len(bodies) == 1, 'replays returned different messages: %d' % len(bodies))
+ check(len(instances) >= 2, 'all requests hit one replica; test does not prove cross-replica')
+ same = [m for m in history(c, bob, chat) if m['text'] == text]
+ check(len(same) == 1, 'expected exactly 1 stored message, found %d' % len(same))
+ return '%d parallel requests via %d replicas -> 1 message' % (n, len(instances))
+
+
+@case('replay is semantic: JSON key order/whitespace does not matter; other body -> 409')
+def t_semantic_replay(c, alice, bob, chat):
+ key = uuid.uuid4().hex
+ first = c.call('POST', msg_path(chat), 201, actor=alice, raw=b'{"text":"abc"}',
+ headers={'Idempotency-Key': key, 'Content-Type': 'application/json'}, schema='Message')
+ again = c.call('POST', msg_path(chat), 201, actor=alice, raw=b'{ "text" : "abc" }\n',
+ headers={'Idempotency-Key': key, 'Content-Type': 'application/json'}, schema='Message')
+ check(first['json'] == again['json'], 'replay returned another message')
+ c.call('POST', msg_path(chat), 409, actor=alice, body={'text': 'abd'}, headers={'Idempotency-Key': key})
+ third = c.call('POST', msg_path(chat), 201, actor=alice, body={'text': 'abc'},
+ headers={'Idempotency-Key': key}, schema='Message')
+ check(third['json'] == first['json'], 'stored result changed after 409')
+
+
+@case('key scope = user + chat: same key is independent for other user / other chat')
+def t_key_scope(c, alice, bob, chat):
+ key = 'shared-' + uuid.uuid4().hex
+ a = c.message(alice, chat, 'scope', key=key)['json']
+ b = c.message(bob, chat, 'scope', key=key)['json']
+ chat2 = c.call('POST', '/api/v1/chats', 201, actor=alice,
+ body={'title': 'Второй', 'member_ids': [alice['id'], bob['id']]}, schema='Chat')['json']
+ a2 = c.message(alice, chat2, 'scope', key=key)['json']
+ check(len({a['id'], b['id'], a2['id']}) == 3, 'scopes collided')
+ check(b['sender_id'] == bob['id'], 'sender mixed up')
+
+
+@case('replay re-checks the session and chat access')
+def t_replay_rechecks_access(c, alice, bob, chat, eve):
+ key = uuid.uuid4().hex
+ c.message(alice, chat, 'access', key=key)
+ c.call('POST', msg_path(chat), 404, actor=eve, body={'text': 'access'}, headers={'Idempotency-Key': key})
+ c.call('POST', msg_path(chat), 401, body={'text': 'access'}, headers={'Idempotency-Key': key})
+ c.call('POST', msg_path(chat), 404, actor=eve, body={'text': ' '}, headers={'Idempotency-Key': key})
+ c.call('POST', msg_path(chat), 404, actor=eve, body={'text': 'x'})
+
+
+@case('logout is visible on every replica immediately (shared sessions)')
+def t_logout_shared(c, alice, bob, chat):
+ tmp = c.user('tmp')
+ c.call('GET', '/api/v1/users/me', actor=tmp, schema='User')
+ c.call('DELETE', '/api/v1/auth/sessions/current', 204, actor=tmp)
+ seen = set()
+ for _ in range(10):
+ seen.add(c.call('GET', '/api/v1/users/me', 401, actor=tmp)['headers']['X-Instance-Id'])
+ check(len(seen) >= 2, 'revocation checked on one replica only')
+ return 'revoked token rejected by %d replicas' % len(seen)
+
+
+def main():
+ import argparse
+ p = argparse.ArgumentParser()
+ p.add_argument('--base-url', default='http://localhost:8080')
+ p.add_argument('--json', default=None)
+ a = p.parse_args()
+ c = Client(a.base_url, timeout=10)
+ alice, bob, eve, chat = c.bootstrap()
+ for t in (t_no_sticky, t_instance_on_errors, t_key_validation, t_concurrent_same_key,
+ t_semantic_replay, t_key_scope, t_logout_shared):
+ t(c, alice, bob, chat)
+ t_replay_rechecks_access(c, alice, bob, chat, eve)
+ failed = [r for r in RESULTS if r['result'] != 'PASS']
+ print('%d/%d passed' % (len(RESULTS) - len(failed), len(RESULTS)))
+ if a.json:
+ Path(a.json).write_text(json.dumps(RESULTS, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
+ sys.exit(1 if failed else 0)
+
+
+if __name__ == '__main__':
+ main()