MVP microservice for transaction data aggregation, developed for the Spirii Backend Developer Coding Challenge.
The microservice collects transactions from the Transaction API and provides aggregated data through its own API endpoints:
- User aggregated data: balance, earned, spent, payout, paid out
- List of requested payouts: user ID, payout amount (with aggregation for individual users)
- NestJS - main framework
- PostgreSQL - aggregated data storage
- Redis - caching for high performance
- TypeORM - ORM for database operations
- Docker Compose - containerization for dev environment
📖 API Usage Examples - Comprehensive API documentation with real examples
🧪 Testing Strategy - Complete testing approach and quality assurance
- Docker and Docker Compose
- Node.js 18+ (for local development)
-
Clone the repository and navigate to the directory:
cd spirii_coding_challenge -
Create .env file from example:
cp config.example.env .env
-
Start all services with Docker Compose:
docker-compose up --build
This will start:
- PostgreSQL (port 5432)
- Redis (port 6379)
- NestJS API (port 3000)
-
API will be available at:
http://localhost:3000 -
Test the API:
# Check system health curl http://localhost:3000/health # Get user aggregates (example) curl http://localhost:3000/users/074092/aggregates # See complete examples in docs/API_EXAMPLES.md
-
Install dependencies:
npm install
-
Start only database and Redis:
docker-compose up postgres redis
-
Run application in dev mode:
npm run start:dev
📖 For complete API documentation with examples, see API_EXAMPLES.md
GET /users/{userId}/aggregatesResponse:
{
"userId": "074092",
"balance": 18.8,
"earned": 100.2,
"spent": 51.4,
"payout": 30.0,
"paidOut": 0.0,
"lastUpdated": "2023-03-16T12:33:11.000Z"
}GET /payouts/requestsResponse:
{
"requests": [
{
"userId": "074092",
"totalAmount": 45.5
},
{
"userId": "074093",
"totalAmount": 100.0
}
]
}GET /health # System health overview
GET /health/database # Database connectivity check
GET /health/sync # Synchronization status
GET /health/metrics # System performance metricsPOST /sync/transactions # Trigger manual sync
GET /sync/status # Get sync history and status- Pre-computed aggregates: Data is aggregated in the background and stored in
user_aggregatestable - Redis caching: Frequently accessed data is cached to reduce database load
- Indexing: Optimized indexes for fast queries by
user_id,created_at,type
- Periodic tasks: Synchronization every minute (configurable via
SYNC_INTERVAL_MINUTES) - Batch processing: Processing up to 1000 transactions at a time
- Rate limiting: Compliance with Transaction API limits (5 requests per minute)
- Incremental updates: Fetching only new transactions since last synchronization
- Graceful error handling: Error logging without stopping synchronization
- Transaction safety: Using database transactions for data consistency
- Monitoring:
sync_statustable for tracking synchronization state
🧪 For detailed testing strategy and examples, see TESTING_STRATEGY.md
# Unit tests
npm run test
# E2E tests
npm run test:e2e
# Test coverage
npm run test:cov- Unit Tests: Comprehensive testing with Jest and NestJS utilities
- Health Monitoring: Real-time system status endpoints
- Input Validation: Global validation with class-validator
- Error Handling: Graceful error scenarios and recovery
- Performance Testing: Load testing examples and monitoring
See config.example.env for a complete list of available settings.
- transactions - storage of original transactions
- user_aggregates - pre-computed user aggregates
- payout_requests - tracking of payout requests
- sync_status - synchronization monitoring
- Mock Transaction API: Current implementation uses a mock API
- Simple authentication: Not implemented in MVP version
- Minimal validation: Basic input data validation
- Single instance: Not optimized for horizontal scaling
spirii_coding_challenge/
├── docs/ # Documentation
│ ├── API_EXAMPLES.md # Complete API usage examples
│ └── TESTING_STRATEGY.md # Testing approach and quality assurance
├── src/
│ ├── aggregation/ # User data aggregation module
│ ├── entities/ # Database entities (TypeORM)
│ ├── health/ # Health check and monitoring
│ ├── sync/ # Transaction synchronization
│ └── transaction-api/ # Mock Transaction API
├── docker-compose.yml # Development environment
├── init.sql # Database schema initialization
└── config.example.env # Environment variables template
- 📖 Complete API Documentation - Real examples with curl commands
- 🧪 Testing Strategy - Comprehensive testing approach
- 🐳 Docker Setup - Multi-container development environment
- 🗄️ Database Schema - PostgreSQL table definitions and indexes
Challenge: Spirii Backend Developer Recruiting Challenge
Framework: NestJS + TypeORM + PostgreSQL + Redis
MVP Focus: Data aggregation with high performance and reliability