Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions participantes/caio-callegario/README.md
Original file line number Diff line number Diff line change
@@ -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
94 changes: 94 additions & 0 deletions participantes/caio-callegario/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions participantes/caio-callegario/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
29 changes: 29 additions & 0 deletions participantes/caio-callegario/postgres/init.sql
Original file line number Diff line number Diff line change
@@ -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));