Quick Setup

This directory contains scripts to quickly set up and test the microservices coordination examples from Chapter 3.

๐Ÿš€ Quick Start

The fastest way to try the example with zero local dependencies:

# Download and run the setup script
curl -fsSL https://raw.githubusercontent.com/tasker-systems/tasker/main/spec/blog/post_03_microservices_coordination/setup-scripts/blog-setup.sh | bash

# Or with custom app name
curl -fsSL https://raw.githubusercontent.com/tasker-systems/tasker/main/spec/blog/post_03_microservices_coordination/setup-scripts/blog-setup.sh | bash -s -- --app-name my-microservices-demo

Requirements: Docker and Docker Compose only

Local Setup

If you prefer to run the setup script locally:

# Download the script
curl -fsSL https://raw.githubusercontent.com/tasker-systems/tasker/main/spec/blog/post_03_microservices_coordination/setup-scripts/blog-setup.sh -o blog-setup.sh
chmod +x blog-setup.sh

# Run with options
./blog-setup.sh --app-name microservices-demo --output-dir ./demos

๐Ÿ› ๏ธ How It Works

Docker-Based Architecture

The setup script creates a complete Docker environment with:

  • Rails application with live code reloading

  • PostgreSQL 15 database

  • Redis 7 for background job processing

  • Sidekiq for workflow execution

  • All tested code examples from the GitHub repository

Integration with Tasker Repository

All code examples are downloaded directly from the tested repository:

This ensures the examples are always up-to-date and have passed integration tests.

๐Ÿ“‹ What Gets Created

Application Structure

API Endpoints

  • POST /user_onboarding - Start user onboarding workflow

  • GET /user_onboarding/status/:task_id - Monitor onboarding progress

  • GET /user_onboarding/results/:task_id - Get onboarding results

๐Ÿงช Testing the Microservices Coordination

Start the Application

Wait for all services to be ready (you'll see "Ready for connections" messages).

Create New User Account

Monitor Onboarding Progress

Get Onboarding Results

Test with Different Plan Types

๐Ÿ”ง Key Features Demonstrated

Service Orchestration

The workflow demonstrates coordination across multiple services:

  • User service for account creation

  • Billing service for payment setup

  • Notification service for welcome emails

  • Each service has its own retry and timeout policies

Circuit Breaker Pattern

Built-in resilience against service failures:

  • Automatic retry for transient failures

  • Circuit breaker prevents cascading failures

  • Graceful degradation when services are unavailable

Structured Input Validation

Comprehensive validation of complex nested data:

  • User information validation (email, phone, names)

  • Billing information validation (plan types, payment methods)

  • Preferences validation (consent, notification settings)

  • Type safety and schema enforcement

API Abstraction

Clean separation between business logic and API handling:

  • Step handlers focus on business logic

  • API concerns handle service integration

  • Consistent error handling across services

  • Correlation ID tracking for distributed tracing

Idempotency Handling

Safe retry of operations:

  • Duplicate detection for user creation

  • Idempotent billing setup

  • Safe preference updates

๐Ÿ” Monitoring and Observability

Docker Logs

Workflow Monitoring

Service Health Tracking

Each step provides service-specific information:

  • Which service was called

  • Response times and status codes

  • Retry attempts and failure reasons

  • Correlation IDs for distributed tracing

๐Ÿ› ๏ธ Customization

Adding New Services

  1. Create a new API concern for the service

  2. Create a step handler that uses the concern

  3. Add the step to the YAML configuration

Example:

Modifying Service Behavior

Update the API concerns to change service interaction:

Adjusting Retry Policies

Update the YAML configuration for different services:

๐Ÿ”ง Troubleshooting

Common Issues

Docker services won't start:

  • Ensure Docker is running: docker --version

  • Check for port conflicts: docker-compose ps

  • Free up resources: docker system prune

Workflow doesn't start:

  • Ensure all services are healthy: docker-compose ps

  • Check Sidekiq is running: docker-compose logs sidekiq

  • Verify database is ready: docker-compose exec web rails db:migrate:status

Service calls fail:

  • Check network connectivity between containers

  • Verify service URLs in the API concerns

  • Review correlation IDs in logs for distributed tracing

  • Check for authentication or authorization issues

Steps fail with validation errors:

  • Verify input data matches the YAML schema

  • Check for required fields in nested objects

  • Ensure data types match expectations (strings, booleans, etc.)

Getting Help

  1. Check service status: docker-compose ps

  2. View logs: docker-compose logs -f

  3. Restart services: docker-compose restart

  4. Clean restart: docker-compose down && docker-compose up

๐Ÿ“– Learn More

๐Ÿ›‘ Cleanup

When you're done experimenting:

๐Ÿ’ก Next Steps

Once you have the workflow running:

  1. Experiment with service failures - Simulate network timeouts and service unavailability

  2. Customize the business logic - Add new validation rules or service integrations

  3. Add new services - Extend with additional microservices

  4. Implement real integrations - Replace mock services with real APIs

  5. Scale the coordination - Test with multiple concurrent workflows

The patterns demonstrated here scale from simple service orchestration to complex distributed systems with dozens of microservices.

Last updated