Skip to content

Commit 589a4a9

Browse files
Merge pull request #16 from Yedidyar/orchestration-and-architecture
Orchestration and architecture
2 parents c616172 + 4f1d3ef commit 589a4a9

File tree

4 files changed

+485
-0
lines changed

4 files changed

+485
-0
lines changed

analytics-project/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:18-alpine
2+
3+
WORKDIR /app
4+
5+
# Copy package files
6+
COPY package*.json ./
7+
COPY tsconfig.json ./
8+
9+
# Install dependencies
10+
RUN npm ci --only=production
11+
12+
# Copy source code
13+
COPY . .
14+
15+
# Build the application (optional - can be overridden)
16+
RUN npm run build || true
17+
18+
# Expose default port (can be overridden)
19+
EXPOSE 3000
20+
21+
# Default command (can be overridden)
22+
CMD ["npm", "run", "start"]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Analytics Architecture Diagram
2+
3+
```mermaid
4+
graph TB
5+
%% External traffic
6+
Client[Client/Browser] --> API[API Gateway]
7+
8+
%% Main queue
9+
API --> PVQ[page_views Queue<br/>RabbitMQ]
10+
11+
%% Partitioner service
12+
PVQ --> Partitioner[Partitioner Service]
13+
14+
%% Partitioned queues
15+
Partitioner --> PV0[page_views_0<br/>RabbitMQ]
16+
Partitioner --> PV1[page_views_1<br/>RabbitMQ]
17+
Partitioner --> PV2[page_views_2<br/>RabbitMQ]
18+
Partitioner --> PVN[page_views_n-1<br/>RabbitMQ]
19+
20+
%% Aggregator services
21+
PV0 --> Agg0[Aggregator_0<br/>Service]
22+
PV1 --> Agg1[Aggregator_1<br/>Service]
23+
PV2 --> Agg2[Aggregator_2<br/>Service]
24+
PVN --> AggN[Aggregator_n-1<br/>Service]
25+
26+
%% Final destination
27+
Agg0 --> IncSvc[Increments Service]
28+
Agg1 --> IncSvc
29+
Agg2 --> IncSvc
30+
AggN --> IncSvc
31+
32+
%% Styling
33+
classDef queue fill:#e1f5fe,stroke:#01579b,stroke-width:2px
34+
classDef service fill:#f3e5f5,stroke:#4a148c,stroke-width:2px
35+
classDef gateway fill:#e8f5e8,stroke:#1b5e20,stroke-width:2px
36+
classDef client fill:#fff3e0,stroke:#e65100,stroke-width:2px
37+
38+
class PVQ,PV0,PV1,PV2,PVN queue
39+
class Partitioner,Agg0,Agg1,Agg2,AggN service
40+
class API gateway
41+
class Client client
42+
class IncSvc service
43+
```
44+
45+
## Architecture Flow
46+
47+
1. **API Gateway**: Receives page view requests from clients and writes them to the main `page_views` queue
48+
2. **Partitioner Service**: Reads from `page_views` queue and distributes messages across N partitioned queues (`page_views_0` to `page_views_n-1`)
49+
3. **Aggregator Services**: Each aggregator service (0 to n-1) reads from its respective partitioned queue and:
50+
- Processes up to 1000 messages OR waits 1 minute (whichever comes first)
51+
- Aggregates messages by pages
52+
- Writes aggregated data to the increments service
53+
54+
## Components
55+
56+
- **API Gateway**: Entry point for page view data
57+
- **RabbitMQ Queues**:
58+
- `page_views`: Main queue for incoming data
59+
- `page_views_0` to `page_views_n-1`: Partitioned queues for parallel processing
60+
- **Partitioner Service**: Distributes load across partitions
61+
- **Aggregator Services**: Process and aggregate data in parallel
62+
- **Increments Service**: Final destination for aggregated analytics data

analytics-project/architecture.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
New Architecture parts:
2+
3+
1. API Gateway that writes to a queue raw_views
4+
2. Partitioner service that reads from the raw_views queue and partitions it between n queues raw_views_0->raw_views_n-1
5+
3. Aggregator service per each n queue that reads from the queue and every 1000 messages/1 minutes (whichever comes first) aggregates the messages it got by pages and makes a request to the increments_service
6+
7+
What do we need?
8+
Api gateway
9+
raw*views queue (RabbitMQ)
10+
page_views\*(0-n) (RabbitMQ)
11+
partitioner service (reads from raw_views and writes to raw_views*(0-n))
12+
aggregator\*(0-n) service that reads from raw*views*(0-n) and writes to the increments_service
13+
14+
Workload:
15+
api gateway-Assaf
16+
the API gateway has 3 routes
17+
GET /report/{page}?now={now}&order={asc|desc}&take={1-24}
18+
forwards requests as proxy to the anlytics service
19+
POST /page-views/single/
20+
parse to the multi schema and writes the payload to the raw_views queue
21+
POST /page-views/multi/
22+
writes the payload to the raw_views queue
23+
24+
and every request is queued to the raw_views queue
25+
aggregator-
26+
basically performs only /multi requests
27+
partitioner- basically a queue load balancer to queues
28+
deployment-

0 commit comments

Comments
 (0)