π₯ Event-Driven Notification System with TypeScript, SQS, SNS, and Postgres
Build a simplified microservice architecture that demonstrates an event-driven pipeline:
- Receives events via a webhook (HTTP).
- Publishes those events to an SNS topic.
- Routes events to multiple SQS queues subscribed to the topic.
- Consumes those events asynchronously.
- Persists them into a PostgreSQL database via Amazon RDS.
- Optionally logs or alerts based on event type.
β
βββ src/
β βββ consumers/
β β βββ loggerConsumer.ts # Logs event details
β β βββ databaseConsumer.ts # Writes events to local PostgreSQL
β βββ publisher/
β β βββ snsPublisher.ts # Publishes to SNS
β βββ server/
β β βββ routes/
β β β βββ user.ts
β β βββ index.ts # HTTP webhook for events
β βββ services/
β β βββ db.ts # Postgres client and table schema
β βββ types/
β βββ events.ts # TypeScript event interfaces
β
βββ docker/
β βββ postgres.Dockerfile # Optional: local Postgres setup
β
βββ scripts/
β βββ setupAWSResources.sh # Bootstrap SNS & SQS
β
βββ package.json
βββ tsconfig.json
βββ README.md
-
π§ Setup Project Initialize TypeScript project, install dependencies, and create base folder structure.
-
π Create Webhook Receiver
Build a Hapi server that accepts JSON events via POST, validates structure. -
π€ Implement SNS Publisher
Use@aws-sdk/client-snsto publish incoming events to the SNS topic. -
π¬ Build SQS Logger Consumer Poll an SQS queue and log each event's contents to the console.
-
ποΈ Build SQS Postgres Consumer Store relevant fields from incoming events into the local PostgreSQL DB.
-
π’οΈ Setup Local PostgreSQL
Run a Postgres container via Docker and create necessary tables/schema. -
π§ͺ Define Event Types Create reusable TypeScript interfaces/types for
user_signed_up,order_placed, etc. -
π§ͺ Write Unit Tests Add moccha-based tests for publisher and consumer logic.
-
π§° Write AWS Infra Script
Bash or Node.js script to create SNS topic, SQS queues, and subscriptions. -
π Finalize Documentation
Update README with setup instructions, architecture diagram (optional), and usage notes.
Each event is a JSON payload like:
{
"type": "order_placed",
"payload": {
"order_id": "xyz789",
"user_id": "123",
"total": 49.99,
"timestamp": "2025-06-25T10:25:00Z"
}
}