forked from evgenyvinnik/llm-driven-system-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
208 lines (198 loc) · 4.66 KB
/
docker-compose.yml
File metadata and controls
208 lines (198 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
services:
# PostgreSQL Database
postgres:
image: postgres:16-alpine
container_name: scalable-api-postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: scalable_api
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./backend/src/db/init.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
networks:
- scalable-api-network
# Redis Cache
redis:
image: valkey/valkey:7-alpine
container_name: scalable-api-redis
ports:
- "6379:6379"
volumes:
- redis_data:/data
command: redis-server --appendonly yes
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
networks:
- scalable-api-network
# RabbitMQ Message Broker
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: scalable-api-rabbitmq
ports:
- "5672:5672"
- "15672:15672"
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 10s
timeout: 5s
retries: 3
networks:
- scalable-api-network
# API Server Instance 1
api-server-1:
build:
context: ./backend
dockerfile: Dockerfile
container_name: scalable-api-server-1
environment:
- PORT=3001
- INSTANCE_ID=api-1
- NODE_ENV=production
- POSTGRES_HOST=postgres
- REDIS_HOST=redis
ports:
- "3001:3001"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3001/health"]
interval: 10s
timeout: 5s
retries: 3
networks:
- scalable-api-network
# API Server Instance 2
api-server-2:
build:
context: ./backend
dockerfile: Dockerfile
container_name: scalable-api-server-2
environment:
- PORT=3002
- INSTANCE_ID=api-2
- NODE_ENV=production
- POSTGRES_HOST=postgres
- REDIS_HOST=redis
ports:
- "3002:3002"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3002/health"]
interval: 10s
timeout: 5s
retries: 3
networks:
- scalable-api-network
# API Server Instance 3
api-server-3:
build:
context: ./backend
dockerfile: Dockerfile
container_name: scalable-api-server-3
environment:
- PORT=3003
- INSTANCE_ID=api-3
- NODE_ENV=production
- POSTGRES_HOST=postgres
- REDIS_HOST=redis
ports:
- "3003:3003"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3003/health"]
interval: 10s
timeout: 5s
retries: 3
networks:
- scalable-api-network
# Load Balancer
load-balancer:
build:
context: ./backend
dockerfile: Dockerfile.lb
container_name: scalable-api-load-balancer
environment:
- LB_PORT=3000
- API_SERVERS=http://api-server-1:3001,http://api-server-2:3002,http://api-server-3:3003
- NODE_ENV=production
ports:
- "3000:3000"
depends_on:
- api-server-1
- api-server-2
- api-server-3
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 10s
timeout: 5s
retries: 3
networks:
- scalable-api-network
# API Gateway
gateway:
build:
context: ./backend
dockerfile: Dockerfile.gateway
container_name: scalable-api-gateway
environment:
- GATEWAY_PORT=8080
- REDIS_HOST=redis
- POSTGRES_HOST=postgres
- NODE_ENV=production
ports:
- "8080:8080"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 10s
timeout: 5s
retries: 3
networks:
- scalable-api-network
# Frontend (for production)
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: scalable-api-frontend
ports:
- "80:80"
depends_on:
- gateway
networks:
- scalable-api-network
volumes:
postgres_data:
redis_data:
networks:
scalable-api-network:
driver: bridge