From 7b9f34f2d73738297edcbede486811c45eed818b Mon Sep 17 00:00:00 2001 From: Caio Callegario Date: Mon, 1 Dec 2025 23:29:58 -0300 Subject: [PATCH] =?UTF-8?q?Submiss=C3=A3o=20Teste=20-=20Caio=20Callegario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Submissão teste --- participantes/caio-callegario/README.md | 14 +++ .../caio-callegario/docker-compose.yml | 94 +++++++++++++++++++ participantes/caio-callegario/nginx.conf | 21 +++++ .../caio-callegario/postgres/init.sql | 29 ++++++ 4 files changed, 158 insertions(+) create mode 100644 participantes/caio-callegario/README.md create mode 100644 participantes/caio-callegario/docker-compose.yml create mode 100644 participantes/caio-callegario/nginx.conf create mode 100644 participantes/caio-callegario/postgres/init.sql diff --git a/participantes/caio-callegario/README.md b/participantes/caio-callegario/README.md new file mode 100644 index 0000000..ea3c62e --- /dev/null +++ b/participantes/caio-callegario/README.md @@ -0,0 +1,14 @@ +# Submissão Teste Backend – Controle de Concorrência + +**Caio Callegario** + +Submissão feita com: + +- **Nginx** como load balancer +- **PostgreSQL** como banco de dados +- **Java 21 + Spring Boot** para a API +- **JDBC Template** para acesso ao banco +- **Docker Compose** para orquestração + +**Repositório da API:** +https://github.com/callegariodev/backend-test diff --git a/participantes/caio-callegario/docker-compose.yml b/participantes/caio-callegario/docker-compose.yml new file mode 100644 index 0000000..f2c3a51 --- /dev/null +++ b/participantes/caio-callegario/docker-compose.yml @@ -0,0 +1,94 @@ +services: + + api01: &api + image: callegariodev/sizebay-api:latest + hostname: api01 + + environment: + DB_HOST: db + DB_PORT: 5432 + DB_NAME: sizebay-backend-challenge + DB_USERNAME: sizebay + DB_PASSWORD: backend-challenge + + SPRING_DATASOURCE_HIKARI_MAXIMUM_POOL_SIZE: 15 + SPRING_DATASOURCE_HIKARI_MINIMUM_IDLE: 5 + + SERVER_TOMCAT_MAX_THREADS: 150 + SERVER_TOMCAT_ACCEPT_COUNT: 200 + + JAVA_TOOL_OPTIONS: > + -XX:+UseG1GC + -Xms128m + -Xmx128m + -XX:MaxMetaspaceSize=64m + + depends_on: + - db + + deploy: + resources: + limits: + cpus: "0.45" + memory: "150MB" + + + api02: + <<: *api + hostname: api02 + + + nginx: + image: nginx:latest + hostname: lb + + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf:ro + + depends_on: + - api01 + - api02 + + ports: + - "9999:9999" + + deploy: + resources: + limits: + cpus: "0.05" + memory: "10MB" + + + db: + image: postgres:16-alpine + hostname: db + + environment: + POSTGRES_PASSWORD: backend-challenge + POSTGRES_USER: sizebay + POSTGRES_DB: sizebay-backend-challenge + + volumes: + - ./postgres/init.sql:/docker-entrypoint-initdb.d/init.sql + + command: > + postgres + -c max_connections=40 + -c shared_buffers=64MB + -c effective_cache_size=128MB + -c work_mem=2MB + -c maintenance_work_mem=32MB + -c synchronous_commit=0 + -c full_page_writes=0 + -c max_wal_size=1024 + + deploy: + resources: + limits: + cpus: "0.45" + memory: "180MB" + + +networks: + default: + driver: bridge \ No newline at end of file diff --git a/participantes/caio-callegario/nginx.conf b/participantes/caio-callegario/nginx.conf new file mode 100644 index 0000000..853f629 --- /dev/null +++ b/participantes/caio-callegario/nginx.conf @@ -0,0 +1,21 @@ +events { + worker_connections 1000; +} + +http { + access_log off; + sendfile on; + + upstream api { + server api01:8080; + server api02:8080; + } + + server { + listen 9999; + + location / { + proxy_pass http://api; + } + } +} \ No newline at end of file diff --git a/participantes/caio-callegario/postgres/init.sql b/participantes/caio-callegario/postgres/init.sql new file mode 100644 index 0000000..af84bf6 --- /dev/null +++ b/participantes/caio-callegario/postgres/init.sql @@ -0,0 +1,29 @@ +CREATE TABLE accounts ( + id SERIAL PRIMARY KEY, + credit_limit BIGINT NOT NULL, + balance BIGINT NOT NULL DEFAULT 0 +); + +CREATE TABLE transactions ( + id SERIAL PRIMARY KEY, + account_id INT NOT NULL, + amount BIGINT NOT NULL, + type CHAR(1) NOT NULL, + description VARCHAR(10) NOT NULL, + occurred_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + CONSTRAINT fk_transactions_account + FOREIGN KEY (account_id) REFERENCES accounts(id) +); + + +CREATE INDEX idx_transactions_account_id_occurred_at ON transactions (account_id, occurred_at DESC); + + +INSERT INTO accounts (id, credit_limit, balance) VALUES +(1, 100000, 0), +(2, 80000, 0), +(3, 1000000, 0), +(4, 10000000, 0), +(5, 500000, 0); + +SELECT setval('accounts_id_seq', (SELECT MAX(id) FROM accounts)); \ No newline at end of file