-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
258 lines (249 loc) · 6.22 KB
/
docker-compose.yml
File metadata and controls
258 lines (249 loc) · 6.22 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
services:
postgres:
image: postgres:16-alpine
container_name: events-postgres
environment:
POSTGRES_DB: events_db
POSTGRES_USER: events_user
POSTGRES_PASSWORD: events_pass
POSTGRES_SHARED_BUFFERS: 4GB
POSTGRES_EFFECTIVE_CACHE_SIZE: 12GB
POSTGRES_WORK_MEM: 64MB
POSTGRES_MAINTENANCE_WORK_MEM: 1GB
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
command: |
postgres
-c max_connections=1000
-c shared_buffers=4GB
-c effective_cache_size=12GB
-c work_mem=64MB
-c maintenance_work_mem=1GB
-c wal_buffers=128MB
-c synchronous_commit=off
-c commit_delay=5000
-c commit_siblings=10
-c max_wal_size=16GB
-c min_wal_size=4GB
-c checkpoint_timeout=20min
-c checkpoint_completion_target=0.9
-c effective_io_concurrency=300
-c random_page_cost=1.1
-c seq_page_cost=1.0
-c autovacuum_max_workers=6
-c autovacuum_naptime=5s
-c autovacuum_vacuum_scale_factor=0.02
-c autovacuum_analyze_scale_factor=0.01
-c bgwriter_delay=100ms
-c bgwriter_lru_maxpages=200
-c bgwriter_lru_multiplier=4.0
-c max_wal_senders=0
-c wal_level=minimal
healthcheck:
test: ["CMD-SHELL", "pg_isready -U events_user -d events_db"]
interval: 10s
timeout: 5s
retries: 5
networks:
- events-network
deploy:
resources:
limits:
cpus: '4'
memory: 16G
reservations:
cpus: '2'
memory: 8G
# NATS JetStream - optimized for 50k events/sec
nats:
image: nats:2.10-alpine
container_name: events-nats
ports:
- "4222:4222"
- "8222:8222"
command: ["-c", "/config/nats.conf"]
volumes:
- nats_data:/data
- ./nats.conf:/config/nats.conf:ro
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://localhost:8222/healthz"]
interval: 10s
timeout: 5s
retries: 5
networks:
- events-network
# NATS Prometheus Exporter
nats-exporter:
image: natsio/prometheus-nats-exporter:latest
container_name: nats-exporter
command:
- -varz
- -connz
- -subz
- -jsz=all
- http://nats:8222
ports:
- "7777:7777"
depends_on:
nats:
condition: service_healthy
networks:
- events-network
restart: unless-stopped
ingestion-service:
build:
context: ./services/ingestion-service
dockerfile: Dockerfile
environment:
NODE_ENV: production
PORT: 3001
NATS_URL: nats://nats:4222
NATS_STREAM: EVENTS
NATS_SUBJECT_PREFIX: events
NATS_CONSUMER_NAME: events_processor
ports:
- "3001"
depends_on:
nats:
condition: service_healthy
networks:
- events-network
restart: unless-stopped
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '1'
memory: 1G
# Worker Service - Replicas 1-12 (batch processing, optimized for 50k+ events/sec)
worker-service:
build:
context: ./services/worker-service
dockerfile: Dockerfile
environment:
NODE_ENV: production
PORT: 3000
DATABASE_HOST: postgres
DATABASE_PORT: 5432
DATABASE_NAME: events_db
DATABASE_USER: events_user
DATABASE_PASSWORD: events_pass
DB_LOGGING: false
DB_POOL_MAX: 75
DB_POOL_MIN: 10
NATS_URL: nats://nats:4222
NATS_STREAM: EVENTS
NATS_SUBJECT_PREFIX: events
NATS_CONSUMER_NAME: events_processor
# Removed NATS_QUEUE_GROUP - each worker has its own durable consumer
NATS_BATCH_SIZE: 5000
NATS_CONCURRENCY: 300
# Expose port for Prometheus scraping
ports:
- "3000"
depends_on:
postgres:
condition: service_healthy
nats:
condition: service_healthy
networks:
- events-network
restart: unless-stopped
deploy:
replicas: 4
resources:
limits:
cpus: '3'
memory: 4G
reservations:
cpus: '2'
memory: 3G
# Analytics Service - read-only API
analytics-service:
build:
context: ./services/analytics-service
dockerfile: Dockerfile
container_name: analytics-service
environment:
NODE_ENV: production
PORT: 3002
DATABASE_HOST: postgres
DATABASE_PORT: 5432
DATABASE_NAME: events_db
DATABASE_USER: events_user
DATABASE_PASSWORD: events_pass
DB_LOGGING: false
DB_POOL_MAX: 50
DB_POOL_MIN: 10
ports:
- "3002:3002"
depends_on:
postgres:
condition: service_healthy
networks:
- events-network
restart: unless-stopped
deploy:
resources:
limits:
cpus: '1'
memory: 1G
reservations:
cpus: '0.5'
memory: 512M
# Prometheus - metrics collection
prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=30d'
networks:
- events-network
restart: unless-stopped
# Grafana - dashboards
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3003:3000"
volumes:
- grafana_data:/var/lib/grafana
- ./grafana/provisioning:/etc/grafana/provisioning
- ./grafana/provisioning/dashboards:/var/lib/grafana/dashboards
environment:
GF_SECURITY_ADMIN_PASSWORD: admin
GF_USERS_ALLOW_SIGN_UP: false
networks:
- events-network
restart: unless-stopped
depends_on:
- prometheus
publisher:
image: andriiuni/events
container_name: events-publisher
environment:
EVENT_ENDPOINT: http://ingestion-service:3001/webhook
EVENTS_PER_SECOND: 5000
depends_on:
- ingestion-service
networks:
- events-network
networks:
events-network:
driver: bridge
volumes:
postgres_data:
nats_data:
prometheus_data:
grafana_data: