forked from zanfranceschi/rinha-de-backend-2024-q1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Participação de Danilo Siqueira na Rinha de Backend. (zanfrance…
…schi#1674) * Criação do docker-compose * Tabela de transações * Configuração do nginx. * Referências. * Finalizando. --------- Co-authored-by: Danilo Siqueira <danilo@geodados.com.br>
- Loading branch information
1 parent
039352f
commit 36f173a
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Participação de Danilo da Silva Siqueira na Rinha de Backend 2024 Q1 - Segunda Edição | ||
|
||
Veja como foi minha jornada para participar da Rinha no [YouTube](https://www.youtube.com/@olegadodev). | ||
|
||
[GitHub](https://github.com/danilosiqueira) | ||
| [Repositório](https://github.com/danilosiqueira/rinha-de-backend-2024-q1-api) | ||
| [LinkedIn](https://www.linkedin.com/in/danilo-da-silva-siqueira/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
version: "3.5" | ||
|
||
services: | ||
api01: &api | ||
# Lembre-se de que seu serviço HTTP deve estar hospedado num repositório | ||
# publicamente acessível! Ex.: hub.docker.com | ||
image: danilosiqueira/rinha-de-backend-api:latest | ||
hostname: api01 | ||
environment: | ||
- DB_HOSTNAME=db | ||
|
||
# # Não é necessário expor qualquer porta além da porta do load balancer, | ||
# # mas é comum as pessoas o fazerem para testarem suas APIs e conectarem | ||
# # ao banco de dados na fase de desenvolvimento. | ||
ports: | ||
- "8081:8080" | ||
depends_on: | ||
- db | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.6" | ||
memory: "200MB" | ||
|
||
api02: | ||
# # Essa sintaxe reusa o que foi declarado em 'api01'. | ||
<<: *api | ||
hostname: api02 | ||
environment: | ||
- DB_HOSTNAME=db | ||
ports: | ||
- "8082:8080" | ||
|
||
nginx: | ||
image: nginx:latest | ||
volumes: | ||
- ./nginx.conf:/etc/nginx/nginx.conf:ro | ||
depends_on: | ||
- api01 | ||
- api02 | ||
ports: | ||
# Obrigatório expor/usar a porta 9999 no load balancer! | ||
- "9999:9999" | ||
deploy: | ||
resources: | ||
limits: | ||
cpus: "0.17" | ||
memory: "10MB" | ||
|
||
db: | ||
image: postgres:latest | ||
hostname: db | ||
environment: | ||
- POSTGRES_USER=admin | ||
- POSTGRES_PASSWORD=123 | ||
- POSTGRES_DB=rinha | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- ./script.sql:/docker-entrypoint-initdb.d/script.sql | ||
deploy: | ||
resources: | ||
limits: | ||
# Note que a soma de todos os limites dos serviços | ||
# aqui declarados é de 1.5 unidades de CPU e 550MB | ||
# de memória. A distribuição feita aqui é apenas | ||
# um exemplo – distribua como quiser. | ||
cpus: "0.13" | ||
memory: "140MB" | ||
|
||
# O uso do modo `bridge` deve ser adequado à carga que será usada no teste. | ||
# A edição anterior se beneficiou do modo host pois o volume de requisições | ||
# era relativamente alto e a virtualização da rede se tornou um gargalo, mas | ||
# este modo é mais complexo de ser configurado. Fique à vontade para usar o | ||
# modo que quiser desde que não conflite com portas trivialmente usadas em um | ||
# SO. | ||
networks: | ||
default: | ||
driver: bridge | ||
name: rinha-nginx-2024q1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; # Lembra da porta 9999 obrigatória? | ||
|
||
location / { | ||
proxy_pass http://api; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
CREATE TABLE clientes ( | ||
id serial not null primary key, | ||
nome varchar(100) not null, | ||
limite bigint not null default 0, | ||
saldo bigint not null default 0 | ||
); | ||
|
||
CREATE TABLE transacoes ( | ||
id serial not null primary key, | ||
valor bigint not null, | ||
tipo char(1) not null, | ||
descricao varchar(10), | ||
realizada_em timestamp not null default CURRENT_TIMESTAMP, | ||
cliente_id integer not null references clientes (id) | ||
); | ||
|
||
CREATE INDEX idx_transacoes_cliente_id ON transacoes (cliente_id); | ||
|
||
DO $$ | ||
BEGIN | ||
INSERT INTO clientes (nome, limite) | ||
VALUES | ||
('o barato sai caro', 1000 * 100), | ||
('zan corp ltda', 800 * 100), | ||
('les cruders', 10000 * 100), | ||
('padaria joia de cocaia', 100000 * 100), | ||
('kid mais', 5000 * 100); | ||
END; $$ |