Live Demo
The application is deployed on Render:- API: https://blackjack-api-latest-vz8x.onrender.com
- Swagger UI: https://blackjack-api-latest-vz8x.onrender.com/swagger-ui.html
Deployment to Render
Render is a cloud platform that provides automatic deployments from Docker images.Prerequisites
- GitHub account with repository access
- Render account (https://render.com)
- Docker image pushed to Docker Hub or GitHub Container Registry
Setup Steps
1. Create MongoDB Database
- In Render Dashboard, click New → MongoDB
- Configure:
- Name:
blackjack-mongo - Region: Choose closest to your users
- Plan: Free or Starter
- Name:
- Click Create Database
- Copy the Internal Connection String (looks like
mongodb://...)
2. Create MySQL Database
- Click New → PostgreSQL (or use external MySQL provider like PlanetScale)
- For MySQL specifically, consider:
- Railway: https://railway.app (supports MySQL)
- PlanetScale: https://planetscale.com
- AWS RDS: For production workloads
- Copy the connection details
3. Create Web Service
- Click New → Web Service
- Connect your GitHub repository or use Docker image
- Configure:
- Name:
blackjack-api - Environment: Docker
- Region: Same as databases
- Instance Type: Free or Starter
- Docker Image:
ccasr/blackjack-api:latest
- Name:
4. Configure Environment Variables
Set the following environment variables in Render:5. Deploy
- Click Create Web Service
- Render will automatically:
- Pull the Docker image
- Run database migrations (Flyway)
- Start the application
- Generate a public URL
Production Configuration
The application usesapplication-prod.yml for production deployments:
Deployment to AWS
AWS Elastic Container Service (ECS)
1. Push Image to ECR
2. Create Task Definition
Createtask-definition.json:
3. Create Services
AWS Databases
MongoDB Atlas
Use MongoDB Atlas for managed MongoDB:- Create cluster at https://cloud.mongodb.com
- Whitelist AWS IP ranges
- Get connection string
- Set
SPRING_DATA_MONGODB_URIenvironment variable
Amazon RDS for MySQL
Deployment to Google Cloud Platform (GCP)
Cloud Run
Deployment to Heroku
Using Container Registry
Environment Variables Reference
Required Variables
| Variable | Description | Example |
|---|---|---|
SPRING_PROFILES_ACTIVE | Spring profile to use | prod |
SPRING_DATA_MONGODB_URI | MongoDB connection string | mongodb://user:pass@host:27017/blackjack |
SPRING_R2DBC_URL | R2DBC MySQL connection URL | r2dbc:mysql://host:3306/blackjack |
SPRING_R2DBC_USERNAME | MySQL username | blackjack |
SPRING_R2DBC_PASSWORD | MySQL password | your-password |
SPRING_FLYWAY_URL | JDBC URL for Flyway migrations | jdbc:mysql://host:3306/blackjack |
SPRING_FLYWAY_USER | MySQL user for migrations | blackjack |
SPRING_FLYWAY_PASSWORD | MySQL password for migrations | your-password |
Optional Variables
| Variable | Description | Default |
|---|---|---|
PORT | Server port | 8080 |
SPRING_FLYWAY_ENABLED | Enable database migrations | true |
LOGGING_LEVEL_ROOT | Log level | INFO |
Database Migration
Flyway automatically runs migrations on application startup.Migration Files
Migrations are located insrc/main/resources/db/migration/:
V1__create_player_table.sqlV2__add_indexes.sql- etc.
Manual Migration
If you need to run migrations manually:Health Checks and Monitoring
Health Check Endpoint
The application exposes Spring Boot Actuator health endpoint:Configure Health Checks
Most platforms support automated health checks: Render:- Health Check Path:
/actuator/health - Port:
8080
Security Best Practices
1. Use Secrets Management
Never hardcode credentials. Use platform-specific secret managers:- AWS: AWS Secrets Manager or Systems Manager Parameter Store
- GCP: Secret Manager
- Render: Environment Variables (encrypted)
- Heroku: Config Vars
2. Enable HTTPS
Most cloud platforms provide automatic HTTPS:- Render: Automatic SSL certificates
- Heroku: Automatic SSL
- AWS: Use Application Load Balancer with ACM certificates
- GCP: Cloud Run provides automatic HTTPS
3. Network Security
- Keep databases in private networks
- Use VPC peering or private endpoints
- Configure security groups/firewall rules
- Enable database authentication
4. Update Dependencies
Regularly update:Performance Optimization
1. Connection Pooling
Configure R2DBC connection pool:2. JVM Tuning
Set JVM options for containerized environments:3. Enable Compression
Scaling
Horizontal Scaling
The application is stateless and can be scaled horizontally: Render:- Dashboard → Service → Scale → Adjust instance count
Auto-scaling
Configure auto-scaling based on CPU/memory: AWS ECS Auto Scaling:Troubleshooting
Application Won’t Start
- Check environment variables are set correctly
- Verify database connectivity
- Review application logs
- Ensure Flyway migrations completed successfully
Database Connection Issues
High Memory Usage
Adjust JVM heap size:Continuous Deployment
Set up CI/CD pipelines for automatic deployments:GitHub Actions Example
Cost Optimization
Free Tier Options
- Render: Free tier for web services (spins down after inactivity)
- Railway: $5 free credit per month
- MongoDB Atlas: Free M0 cluster (512MB)
- PlanetScale: Free tier with 5GB storage
Production Recommendations
- API: Render Starter ($7/month) or AWS Fargate
- MongoDB: MongoDB Atlas M10 ($0.08/hour)
- MySQL: AWS RDS db.t3.small ($0.017/hour)
Next Steps
- Docker Deployment - Build custom Docker images
- Docker Compose - Run locally with Docker Compose
- API Reference - Explore API endpoints