Application Deployment Guide v1.0.0

Master the art of deploying, scaling, and managing applications on SLYD with best practices and advanced techniques.

About This Guide

This guide builds upon the Applications documentation, providing deeper insights into deployment strategies, application management, and optimization techniques for real-world use cases.

Deployment Strategies

Choose the right deployment approach based on your application's requirements and business needs.

Blue-Green Deployment

Run two identical production environments with only one active at a time, allowing for zero-downtime deployments and easy rollbacks.

Blue-Green Deployment Diagram

How It Works

1

Set up two identical environments (Blue and Green)

2

Route all traffic to the active environment (e.g., Blue)

3

Deploy new application version to the inactive environment (Green)

4

Test the new version in the inactive environment

5

Switch traffic from Blue to Green (instantly or gradually)

6

Keep the old version (Blue) available for quick rollback if needed

Advantages

  • Zero downtime deployments
  • Instant rollback capability
  • Complete testing in production-identical environment
  • Simplified deployment process

Considerations

  • Requires double the resources during deployment
  • Database schema changes require special handling
  • Session persistence between environments may be challenging

Implementation on SLYD

Blue-Green Deployment with SLYD CLI
# Create Blue and Green instance groups
slyd instance-group create --name my-app-blue --template app-template
slyd instance-group create --name my-app-green --template app-template

# Deploy application to Green environment (inactive)
slyd app deploy --app-id my-application --version v2.0.0 --group my-app-green

# Test application in Green environment
slyd tunnel create --name green-test --group my-app-green --port 8080

# Switch traffic from Blue to Green
slyd load-balancer update --name my-app-lb --active-group my-app-green

# If issues occur, quick rollback to Blue
slyd load-balancer update --name my-app-lb --active-group my-app-blue

Canary Deployment

Gradually roll out a new version to a small subset of users before full deployment, allowing you to test in production with minimal risk.

Canary Deployment Diagram

How It Works

1

Deploy the new version alongside the existing version

2

Route a small percentage of traffic (e.g., 5-10%) to the new version

3

Monitor performance, errors, and user feedback closely

4

Gradually increase traffic to the new version if no issues are found

5

Roll back quickly if problems are detected

6

Complete the migration when confident in the new version

Advantages

  • Reduced risk by limiting exposure to new version
  • Real production testing with actual users
  • Gradual rollout allows for performance monitoring
  • Targeted testing with specific user segments

Considerations

  • More complex to set up than all-at-once deployment
  • Requires sophisticated traffic routing capabilities
  • Multiple versions running simultaneously must be compatible
  • Needs robust monitoring and alerting

Implementation on SLYD

Canary Deployment with SLYD CLI
# Deploy canary version alongside current version
slyd instance-group create --name my-app-canary --size 2 --template app-template
slyd app deploy --app-id my-application --version v2.0.0 --group my-app-canary

# Configure load balancer for canary traffic splitting
slyd load-balancer update --name my-app-lb \
  --primary-group my-app-production --primary-weight 90 \
  --canary-group my-app-canary --canary-weight 10

# Monitor performance metrics
slyd metrics watch --groups my-app-production,my-app-canary \
  --metrics response_time,error_rate,throughput

# Gradually increase traffic to canary
slyd load-balancer update --name my-app-lb \
  --primary-group my-app-production --primary-weight 75 \
  --canary-group my-app-canary --canary-weight 25

# Complete the migration
slyd load-balancer update --name my-app-lb \
  --primary-group my-app-canary --primary-weight 100

# Clean up old deployment
slyd instance-group update --name my-app-production \
  --template app-template-v2

Deployment Pipeline

Establish a robust CI/CD pipeline to automate the build, test, and deployment process across different environments.

CI/CD Pipeline Diagram

Pipeline Stages

Source

Code changes are committed to source control (Git)

GitHub GitLab Bitbucket
Build

Application is compiled, dependencies are resolved, and artifacts are created

Docker Maven npm
Test

Automated tests are run to validate the application's functionality

Jest Selenium JUnit
Security

Security scans check for vulnerabilities and compliance issues

SonarQube Snyk OWASP Scan
Deploy

Application is deployed to target environment (staging, production)

SLYD CLI Terraform Ansible
Monitor

Application performance and health are continuously monitored

Prometheus Grafana SLYD Metrics

Implementation with GitHub Actions

GitHub Actions Workflow for SLYD Deployment
name: SLYD App Deployment

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      
      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '16'
          
      - name: Install dependencies
        run: npm ci
        
      - name: Build
        run: npm run build
        
      - name: Test
        run: npm test
        
      - name: Security scan
        run: npm run security-scan
        
      - name: Upload artifacts
        uses: actions/upload-artifact@v2
        with:
          name: build-artifacts
          path: dist/

  deploy-staging:
    needs: build
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v2
        with:
          name: build-artifacts
          path: dist/
          
      - name: Install SLYD CLI
        run: npm install -g slyd-cli
        
      - name: Configure SLYD
        run: slyd configure --api-key ${{ secrets.SLYD_API_KEY }}
        
      - name: Deploy to staging
        run: |
          slyd app deploy \
            --app-id my-application \
            --version ${{ github.sha }} \
            --environment staging \
            --path dist/
            
      - name: Run smoke tests
        run: |
          slyd tunnel create --name smoke-test --environment staging --port 8080
          npm run smoke-tests -- --url https://smoke-test.slyd.cloud
          
  deploy-production:
    needs: deploy-staging
    runs-on: ubuntu-latest
    environment:
      name: production
      url: https://my-application.slyd.cloud
    steps:
      - uses: actions/download-artifact@v2
        with:
          name: build-artifacts
          path: dist/
          
      - name: Install SLYD CLI
        run: npm install -g slyd-cli
        
      - name: Configure SLYD
        run: slyd configure --api-key ${{ secrets.SLYD_API_KEY }}
        
      - name: Deploy to production (Blue-Green)
        run: |
          # Determine current active environment
          CURRENT_ENV=$(slyd load-balancer get --name my-app-lb --output json | jq -r '.activeGroup')
          
          # Deploy to inactive environment
          if [ "$CURRENT_ENV" == "my-app-blue" ]; then
            TARGET_ENV="my-app-green"
          else
            TARGET_ENV="my-app-blue"
          fi
          
          # Deploy new version
          slyd app deploy \
            --app-id my-application \
            --version ${{ github.sha }} \
            --group $TARGET_ENV \
            --path dist/
            
          # Run validation tests
          slyd tunnel create --name validation-test --group $TARGET_ENV --port 8080
          npm run validation-tests -- --url https://validation-test.slyd.cloud
          
          # Switch traffic
          slyd load-balancer update --name my-app-lb --active-group $TARGET_ENV

Containerization

Leverage containers to improve deployment consistency, scalability, and resource utilization.

Container Benefits for SLYD Deployments

Environment Consistency

Guarantee that your application runs in the same environment across development, testing, and production

Resource Efficiency

Containers are lightweight and share the host OS kernel, allowing for higher density deployment

Scalability

Easily scale applications horizontally by spinning up additional container instances

Isolation

Run multiple applications with different dependencies on the same host without conflicts

Container Workflow on SLYD

Container Workflow on SLYD

Building Containers

Create optimized containers for your applications:

Dockerfile Best Practices
# Use specific version tags for base images
FROM node:16-alpine

# Set working directory
WORKDIR /app

# Copy package files first to leverage layer caching
COPY package*.json ./

# Install dependencies
RUN npm ci --only=production

# Copy application code
COPY . .

# Use non-root user for security
RUN addgroup -g 1001 -S nodejs && \
    adduser -S nodejs -u 1001 && \
    chown -R nodejs:nodejs /app
USER nodejs

# Set environment variables
ENV NODE_ENV production

# Expose application port
EXPOSE 8080

# Use CMD instead of ENTRYPOINT for flexibility
CMD ["node", "server.js"]
Container Optimization Tips
  • Use multi-stage builds to keep images small
  • Minimize layer count by combining related commands
  • Remove unnecessary files and build artifacts
  • Leverage build caching effectively
  • Scan images for vulnerabilities before deployment

Deploying Container Images

SLYD supports direct deployment of container images from public or private container registries.

Public Registry Images
Deploy from Docker Hub
slyd container deploy \
    --image nginx:latest \
    --instance-id inst-abc123 \
    --port 80 \
    --env-vars '{
        "NGINX_HOST": "example.com",
        "NGINX_PORT": "80"
    }'
Private Registry Images
Deploy from Private Registry
# Add registry credentials
slyd registry add \
    --name myregistry \
    --url registry.example.com \
    --username user \
    --password pass

# Deploy from private registry
slyd container deploy \
    --image registry.example.com/myapp:v1.0.0 \
    --instance-id inst-abc123 \
    --registry myregistry \
    --port 8080

Container Networking

Configure networking for container-based applications:

Port Mapping

Map container ports to host ports for external access

Port Mapping Example
slyd container deploy \
    --image myapp:latest \
    --instance-id inst-abc123 \
    --ports '{"8080": 80, "8443": 443}'
Container Network

Create isolated networks for multi-container applications

Network Creation
# Create network
slyd network create --name myapp-network --instance-id inst-abc123

# Deploy containers to network
slyd container deploy \
    --image myapp-frontend:latest \
    --instance-id inst-abc123 \
    --network myapp-network \
    --network-alias frontend \
    --ports '{"80": 8080}'

slyd container deploy \
    --image myapp-backend:latest \
    --instance-id inst-abc123 \
    --network myapp-network \
    --network-alias backend

Multi-Container Orchestration

For complex applications with multiple containers, SLYD provides built-in orchestration capabilities:

Compose-Style Deployment

Deploy multi-container applications using a single configuration file

slyd-compose.yaml
version: '1'
services:
  web:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - web-content:/usr/share/nginx/html
    depends_on:
      - app
    restart: always

  app:
    image: myapp:latest
    environment:
      - DB_HOST=db
      - DB_USER=appuser
      - DB_PASSWORD=apppass
    depends_on:
      - db
    restart: always

  db:
    image: postgres:13
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=appuser
      - POSTGRES_PASSWORD=apppass
      - POSTGRES_DB=myappdb
    restart: always

volumes:
  web-content:
  db-data:
    persistent: true
Deploy Using Compose
slyd compose up \
    --file slyd-compose.yaml \
    --instance-id inst-abc123
Health Checks & Auto-Recovery

Configure health checks for automatic container recovery

Health Check Configuration
slyd container deploy \
    --image myapp:latest \
    --instance-id inst-abc123 \
    --health-check '{
        "type": "http",
        "path": "/health",
        "port": 8080,
        "interval": 30,
        "timeout": 5,
        "retries": 3
    }' \
    --restart-policy '{
        "policy": "on-failure",
        "max_retries": 5
    }'

Application Observability

Implement comprehensive monitoring, logging, and tracing for your applications.

Monitoring

Track application health, performance, and resource utilization in real time.

Infrastructure Metrics
  • CPU, memory, disk, and network utilization
  • Instance health and availability
  • Container resource consumption
Application Metrics
  • Request rates, latencies, and error rates
  • Concurrent connections and sessions
  • Queue depths and processing times
  • Custom business metrics (e.g., orders, users)
User Experience Metrics
  • Page load times and time to interactive
  • API response times as experienced by users
  • Error rates by user region or device type

Setting Up Monitoring

1
Configure SLYD Metrics

Enable built-in metrics collection for instances and applications

Enable Metrics Collection
slyd metrics enable \
    --instance-id inst-abc123 \
    --collection-interval 60 \
    --retention-days 30
2
Set Up Custom Metrics

Implement application-specific metrics using the SLYD Metrics API

Send Custom Metrics
// Node.js example using the SLYD Metrics client
const { SLYDMetrics } = require('slyd-metrics');

const metrics = new SLYDMetrics({
  apiKey: process.env.SLYD_API_KEY
});

// Record a count metric
metrics.count('orders.completed', 1, {
  customer_tier: 'premium',
  region: 'us-east'
});

// Record a timing metric
metrics.timing('payment.processing_time', 250, {
  payment_method: 'credit_card'
});

// Record a gauge metric
metrics.gauge('inventory.level', 42, {
  product_id: 'SKU123'
});
3
Configure Dashboards and Alerts

Set up visualizations and notifications for critical metrics

Create Alert Rule
slyd alert create \
    --name "High Error Rate" \
    --metric "app.error_rate" \
    --threshold 0.05 \
    --operator "gt" \
    --duration 300 \
    --severity "critical" \
    --notification-channels "email,slack" \
    --instance-id inst-abc123

Logging

Capture detailed information about application events, errors, and activities.

Structured Logging

Use structured formats like JSON for machine-processable logs

Structured Logging Example
// Node.js example using Winston
const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  defaultMeta: { service: 'user-service' },
  transports: [
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    new winston.transports.File({ filename: 'combined.log' }),
    new winston.transports.Console({
      format: winston.format.combine(
        winston.format.colorize(),
        winston.format.simple()
      )
    })
  ]
});

// Log with structured metadata
logger.info('User login successful', {
  userId: 'user123',
  loginMethod: 'oauth',
  ipAddress: '192.168.1.1',
  timestamp: new Date().toISOString()
});
Log Aggregation

Collect and centralize logs from all instances and containers

Configure Log Aggregation
slyd logging setup \
    --instance-id inst-abc123 \
    --storage-type s3 \
    --storage-config '{
        "bucket": "my-logs-bucket",
        "prefix": "app-logs/",
        "retention_days": 90
    }' \
    --log-sources '{
        "app": "/var/log/app/*.log",
        "nginx": "/var/log/nginx/*.log",
        "system": "/var/log/syslog"
    }'

SLYD Logging Features

Log Search & Analysis

Query and analyze logs using full-text search and structured filters

Log-Based Alerts

Set up notifications based on log patterns or anomalies

Log Retention & Archiving

Configure retention policies and archive logs to cost-effective storage

Log Security & Compliance

Ensure logs meet security requirements with encryption and access controls

Distributed Tracing

Track requests as they flow through distributed microservices for end-to-end visibility.

Distributed Tracing Diagram

Implementing Distributed Tracing

1
Instrument Your Code

Add tracing instrumentation to your application code

OpenTelemetry Example
2
Configure Trace Collection

Set up trace collection and storage in SLYD

Enable Tracing
slyd tracing setup 
3
Explore and Analyze Traces

Use the SLYD Tracing UI to search, filter, and analyze distributed traces

Open Tracing UI
slyd tracing ui --instance-id inst-abc123

Advanced Best Practices

Follow these recommendations to maximize the efficiency, reliability, and security of your application deployments.

Performance Optimization

Resource Right-Sizing

Regularly analyze application resource usage and adjust instance sizes accordingly

Content Delivery Network (CDN)

Use SLYD's integrated CDN for static assets to reduce load times and server load

Database Optimization

Implement proper indexing, caching, and query optimization for database workloads

Load Testing

Regularly perform load testing to identify bottlenecks before they impact users

Security Hardening

Dependency Scanning

Regularly scan and update dependencies to address security vulnerabilities

Least Privilege Principle

Run applications with minimal required permissions and use service accounts

Secrets Management

Use SLYD's secrets manager instead of hardcoding sensitive information

Network Security

Implement network policies and firewalls to restrict unnecessary traffic

Reliability Engineering

Design for Failure

Assume any component can fail and design your application to handle failures gracefully

Circuit Breakers

Implement circuit breakers to prevent cascading failures in distributed systems

Chaos Engineering

Periodically test system resilience by intentionally introducing failures

Backup and Recovery

Implement and regularly test backup and recovery procedures for critical data

An unhandled error has occurred. Reload 🗙