Deployment Guide - usmantahirr/infobip-notification-service GitHub Wiki

Deployment Guide

This guide provides instructions for deploying the Infobip Notification Service in various environments.

Prerequisites

  • Node.js 18.x or later
  • npm 9.x or later
  • Git
  • Infobip API credentials
  • (Optional) PostgreSQL 14.x or later
  • (Optional) Redis 6.x or later

Environment Setup

  1. Clone the repository:

    git clone https://github.com/usmantahirr/infobip-notification-service.git
    cd infobip-notification-service
  2. Install dependencies:

    npm install
  3. Create environment file:

    cp .env.example .env
  4. Configure environment variables in .env:

    # Application
    NODE_ENV=production
    PORT=3000
    
    # Infobip
    INFOBIP_API_KEY=your_api_key
    INFOBIP_BASE_URL=your_base_url
    INFOBIP_SENDER_EMAIL=your_verified_sender_email
    INFOBIP_SENDER_NUMBER=your_sender_number
    
    # Rate Limiting
    RATE_LIMIT_WINDOW=60000
    RATE_LIMIT_MAX_REQUESTS=100
    
    # (Optional) Database
    DATABASE_URL=postgresql://user:password@localhost:5432/notification_service
    
    # (Optional) Redis
    REDIS_URL=redis://localhost:6379

Local Development

  1. Start the development server:

    npm run dev
  2. Access the API documentation:

    http://localhost:3000/api-docs
    

Production Deployment

Docker Deployment

  1. Build the Docker image:

    docker build -t infobip-notification-service .
  2. Run the container:

    docker run -d \
      -p 3000:3000 \
      -e NODE_ENV=production \
      -e INFOBIP_API_KEY=your_api_key \
      -e INFOBIP_BASE_URL=your_base_url \
      -e INFOBIP_SENDER_EMAIL=your_verified_sender_email \
      -e INFOBIP_SENDER_NUMBER=your_sender_number \
      infobip-notification-service

Kubernetes Deployment

  1. Create a ConfigMap for environment variables:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: notification-service-config
    data:
      NODE_ENV: "production"
      PORT: "3000"
      RATE_LIMIT_WINDOW: "60000"
      RATE_LIMIT_MAX_REQUESTS: "100"
  2. Create a Secret for sensitive data:

    apiVersion: v1
    kind: Secret
    metadata:
      name: notification-service-secrets
    type: Opaque
    data:
      INFOBIP_API_KEY: <base64-encoded-api-key>
      INFOBIP_BASE_URL: <base64-encoded-base-url>
      INFOBIP_SENDER_EMAIL: <base64-encoded-sender-email>
      INFOBIP_SENDER_NUMBER: <base64-encoded-sender-number>
  3. Deploy the application:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: notification-service
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: notification-service
      template:
        metadata:
          labels:
            app: notification-service
        spec:
          containers:
            - name: notification-service
              image: infobip-notification-service:latest
              ports:
                - containerPort: 3000
              envFrom:
                - configMapRef:
                    name: notification-service-config
                - secretRef:
                    name: notification-service-secrets
              resources:
                requests:
                  cpu: "100m"
                  memory: "256Mi"
                limits:
                  cpu: "500m"
                  memory: "512Mi"
              readinessProbe:
                httpGet:
                  path: /health
                  port: 3000
                initialDelaySeconds: 5
                periodSeconds: 10
              livenessProbe:
                httpGet:
                  path: /health
                  port: 3000
                initialDelaySeconds: 15
                periodSeconds: 20
  4. Create a Service:

    apiVersion: v1
    kind: Service
    metadata:
      name: notification-service
    spec:
      selector:
        app: notification-service
      ports:
        - port: 80
          targetPort: 3000
      type: LoadBalancer

AWS ECS Deployment

  1. Create an ECR repository:

    aws ecr create-repository --repository-name infobip-notification-service
  2. Push the Docker image:

    aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com
    docker tag infobip-notification-service:latest aws_account_id.dkr.ecr.region.amazonaws.com/infobip-notification-service:latest
    docker push aws_account_id.dkr.ecr.region.amazonaws.com/infobip-notification-service:latest
  3. Create an ECS task definition:

    {
      "family": "notification-service",
      "networkMode": "awsvpc",
      "requiresCompatibilities": ["FARGATE"],
      "cpu": "256",
      "memory": "512",
      "containerDefinitions": [
        {
          "name": "notification-service",
          "image": "aws_account_id.dkr.ecr.region.amazonaws.com/infobip-notification-service:latest",
          "portMappings": [
            {
              "containerPort": 3000,
              "protocol": "tcp"
            }
          ],
          "environment": [
            {
              "name": "NODE_ENV",
              "value": "production"
            }
          ],
          "secrets": [
            {
              "name": "INFOBIP_API_KEY",
              "valueFrom": "arn:aws:ssm:region:account:parameter/notification-service/INFOBIP_API_KEY"
            }
          ],
          "logConfiguration": {
            "logDriver": "awslogs",
            "options": {
              "awslogs-group": "/ecs/notification-service",
              "awslogs-region": "region",
              "awslogs-stream-prefix": "ecs"
            }
          }
        }
      ]
    }

Monitoring

Current Implementation

  • Winston logging
  • Basic error tracking
  • Rate limit monitoring

Planned Improvements

  1. Metrics Collection

    • Prometheus metrics
    • Custom metrics for:
      • Request counts
      • Error rates
      • Response times
      • Queue sizes
  2. Logging

    • Structured logging
    • Log aggregation
    • Log retention policies
  3. Tracing

    • OpenTelemetry integration
    • Distributed tracing
    • Performance monitoring

Scaling

Current Implementation

  • Horizontal scaling via container orchestration
  • Rate limiting per instance
  • Basic load balancing

Planned Improvements

  1. Database Scaling

    • Read replicas
    • Connection pooling
    • Query optimization
  2. Caching Layer

    • Redis caching
    • Cache invalidation
    • Cache warming
  3. Queue Management

    • Message prioritization
    • Dead letter queues
    • Retry policies

Security

Current Implementation

  • API key authentication
  • Rate limiting
  • Security headers
  • CORS configuration

Planned Improvements

  1. Authentication

    • JWT support
    • OAuth2 integration
    • API key rotation
  2. Network Security

    • WAF integration
    • DDoS protection
    • VPC configuration
  3. Data Security

    • Encryption at rest
    • TLS 1.3
    • Audit logging

Backup and Recovery

Current Implementation

  • Basic error handling
  • Container health checks
  • Automatic restarts

Planned Improvements

  1. Data Backup

    • Automated backups
    • Point-in-time recovery
    • Backup verification
  2. Disaster Recovery

    • Multi-region deployment
    • Failover procedures
    • Recovery testing
  3. High Availability

    • Load balancing
    • Auto-scaling
    • Circuit breakers

Maintenance

Regular Tasks

  1. Updates

    • Node.js updates
    • Dependency updates
    • Security patches
  2. Monitoring

    • Log analysis
    • Performance monitoring
    • Error tracking
  3. Backup

    • Database backups
    • Configuration backups
    • Recovery testing

Emergency Procedures

  1. Service Outage

    • Incident response
    • Communication plan
    • Recovery steps
  2. Data Issues

    • Data validation
    • Recovery procedures
    • Integrity checks
  3. Security Incidents

    • Incident response
    • Forensic analysis
    • Remediation steps

Last updated: March 5

⚠️ **GitHub.com Fallback** ⚠️