Music Library API

Spring Boot REST API with On-Demand AWS Infrastructure

🎡 Music Library

Checking application status...

Java 17 Spring Boot 3.5.7 MySQL 8.4 AWS ECS Docker Lambda RESTful API

πŸ“‹ Project Overview

The Music Library API is a comprehensive backend application developed as a bootcamp final project and expanded into a 400+ hour deep dive into deployment options, AWS cloud infrastructure, and cost optimization. This RESTful API provides complete CRUD operations for managing a music catalog including artists, albums, and genres.

Built with Spring Boot following best practices for layered architecture. Features a library of 50 artists and 100+ albums. Deployed on AWS with production-grade reliability and professional UX.

Live API address after propagation: http://project.jcarl.net/api
Validation Testing: 182 API requests, 600 tests, 100% pass rate

πŸ’° 98% Cost Reduction Through Architecture Redesign

This project demonstrates real-world cost optimization β€” the same strategies used by companies to reduce cloud spend. By redesigning from always-on to on-demand architecture, monthly costs dropped from ~$55 to ~$1.

~$55
Before (Always-On)
ECS 24/7 + RDS 24/7 + ALB
~$1
After (On-Demand)
Lambda + S3 + pay-per-use compute

How It Works

🌐 Always-On (Pennies/month)

S3 static site + CloudFront CDN + Lambda functions + API Gateway. Always available for a user to launch the app.

⚑ On-Demand (Pay per use)

RDS MySQL + ECS Fargate only run when launched. Auto-shutdown after 30 minutes of inactivity.

⏰ Smart Auto-Shutdown

Lambda monitors CloudWatch CPU metrics. When idle (CPU < 2% for 30 min), it stops ECS and RDS automatically.

🌟 Application Features

πŸ› οΈ Full REST API

Complete CRUD operations for Artists, Albums, and Genres with proper HTTP status codes and standardized error responses.

πŸ”— Complex Relationships

One-to-Many (Artist-Album) and Many-to-Many (Album-Genre) JPA relationships with bidirectional synchronization.

πŸ“„ Pagination & Sorting

All list endpoints support page, size, and sort parameters for efficient data retrieval.

βœ… Input Validation

Bean Validation (JSR-380) with detailed field-level error messages for data integrity.

πŸ“– Interactive API Docs

Swagger UI (OpenAPI 3.0) for exploring and testing endpoints directly in the browser.

πŸ”¬ Comprehensive Testing

Unit tests with Mockito, integration tests with Spring Boot Test, 600 automated tests passing.

🏁 On-Demand Infrastructure

Lambda-orchestrated startup, auto-shutdown after inactivity, 98% cost reduction vs always-on.

πŸ“Š Real-Time Monitoring

Live infrastructure status API showing database and application state with progress tracking.

🎡 Rich Music Library

50 artists and 100+ albums with cover images, loaded via Postman collection for demonstrations.

πŸ› οΈ Technology Stack

For more information please see the detailed GitHub README.

Backend Framework

  • Spring Boot 3.5.7
  • Spring Web MVC
  • Spring Data JPA
  • Spring Validation

Database & ORM

  • MySQL 8.4 LTS (AWS RDS)
  • H2 Database (Testing)
  • Hibernate ORM
  • On-demand start/stop

Development Tools

  • Java 17
  • Maven Build Tool
  • Docker (multi-stage builds)
  • Lombok, Jackson

API & Documentation

  • RESTful Architecture
  • SpringDoc OpenAPI 3
  • Swagger UI
  • Postman Collection

AWS Compute & Storage

  • ECS Fargate (serverless containers)
  • RDS MySQL (managed database)
  • ECR (container registry)
  • S3 + CloudFront (static hosting)

AWS Serverless & Automation

  • Lambda (status, startup, shutdown)
  • API Gateway (REST endpoints)
  • EventBridge (scheduled triggers)
  • CloudWatch (metrics & logs)

AWS Security & Mail

  • IAM (role-based access)
  • ACM (SSL certificates)
  • SES (email notifications)
  • VPC Security Groups

DNS & Networking

  • Namesilo DNS API
  • Dynamic IP automation
  • Container-based DNS updates
  • Direct IP fallback for users

πŸ“‘ API Endpoints

All endpoints prefixed with /api. Full documentation available in the GitHub README.

🎀 Artists

GET /api/artists - Get paginated artists
POST /api/artists - Create artist
GET /api/artists/{id} - Get artist by ID
PUT /api/artists/{id} - Update artist
DELETE /api/artists/{id} - Delete artist
GET /api/artists/{id}/albums - Get albums by artist

πŸ’Ώ Albums

GET /api/albums - Get paginated albums
GET /api/albums/search?q={query} - Search by title or artist
POST /api/albums - Create album
GET /api/albums/{id} - Get album by ID
PUT /api/albums/{id} - Update album
DELETE /api/albums/{id} - Delete album

🎸 Genres

GET /api/genres - Get paginated genres
POST /api/genres - Create genre
GET /api/genres/{id} - Get genre by ID
PUT /api/genres/{id} - Update genre
DELETE /api/genres/{id} - Delete genre
GET /api/genres/{id}/albums - Get albums by genre

πŸ—οΈ On-Demand Architecture

The application uses a serverless-first architecture that scales to zero when not in use. This is the same pattern used by companies to optimize cloud costs for low-traffic applications.

Architecture Components

🌐 Always-On Layer (Pennies/month)

S3 Static Site hosts this launcher page at projectlauncher.jcarl.net
CloudFront + ACM provides HTTPS and CDN caching
API Gateway + Lambda handles status checks and startup requests
EventBridge triggers auto-shutdown Lambda every 5 minutes

πŸ”‘ On-Demand Layer (Pay only when running)

RDS MySQL starts when user clicks "Launch" (~2-3 min startup)
ECS Fargate deploys container once database is available (~2-3 min)
Namesilo DNS automatically updated with new public IP
Spring Boot App serves API at project.jcarl.net

πŸ”Œ Auto-Shutdown System

EventBridge triggers Lambda every 5 minutes
CloudWatch Metrics analyzed for ECS CPU utilization (30-min average)
Threshold: CPU < 2% indicates true idle (no requests)
Shutdown Action stops ECS service and RDS instance automatically

Lambda Functions

πŸ“Š Status Lambda

Queries ECS and RDS state. Returns database status, app status, and public IP. Powers the real-time progress UI.

⚑ Startup Lambda

Orchestrates startup sequence: starts RDS, waits for availability, then starts ECS service. Handles email notifications via SES.

πŸ›‘ Auto-Shutdown Lambda

Monitors CloudWatch CPU metrics. Stops ECS and RDS when idle for 30 minutes. Prevents cost accumulation.

πŸ›€οΈ Deployment Journey

This project evolved through multiple iterations, technology pivots, and 400+ hours of hands-on learning. What started as a bootcamp final project became a comprehensive study in AWS infrastructure and cost optimization.

Project Metrics

πŸ”¨ 115+ Docker Builds

Iterative development through AWS CloudShell and CodeBuild, refining container configuration and startup scripts.

πŸ—οΈ 17+ ECS Task Revisions

Continuous optimization of container settings, environment variables, and resource allocation.

⏱️ 400+ Development Hours

From bootcamp project to production-ready, cost-optimized cloud infrastructure.

Challenges Overcome

🐚 Shell Compatibility (Alpine Linux)

Route 53 DNS scripts failed due to ash vs bash differences. Pivoted to Namesilo API with simple curl commands that work in Alpine's ash shell.

πŸ”„ ECS Circuit Breaker Rollbacks

Tasks repeatedly rolled back due to health check failures during DNS script execution. Simplified startup sequence and increased health check grace period.

πŸ’» Windows LTSB Docker Issues

Local system incompatible with Docker Desktop. Pivoted to AWS CloudShell as primary build environment β€” cloud-based development solved local limitations.

πŸ” IAM Permission Complexity

Learned distinction between task execution role vs task role. Configured proper cross-service permissions for Lambda to access ECS, RDS, and CloudWatch.

🌐 DNS Migration (Route 53 β†’ Namesilo)

Route 53 API too complex for container scripts. Migrated to Namesilo's simpler HTTP API. Sometimes the best solution is the simplest one.

πŸ“ Static File Serving

Spring Boot update disabled default static resources on AWS. Fixed with environment variable: SPRING_WEB_RESOURCES_STATIC_LOCATIONS.

πŸ“„ Swagger Pagination Conflicts

Swagger UI injected invalid sort parameters causing 500 errors. Migrated to explicit @RequestParam declarations for consistent behavior.

πŸ’° Cost Optimization Architecture

Redesigned entire infrastructure: eliminated ALB ($16/mo), implemented Lambda orchestration, built auto-shutdown system with CloudWatch metrics.

βš™οΈ Auto-Shutdown Calibration

Initial 35% CPU threshold was too aggressive β€” shut down active app. Production testing revealed Spring Boot idles at 10-12%. Calibrated to 2% for true idle detection.

πŸ“Š Real-Time Status Monitoring

Built Lambda to extract public IP from ECS task ENI attachments. Required EC2 network interface permissions and handling of various RDS states.

πŸ“§ SES Email Integration

Configured domain verification with DKIM, obtained production access, implemented async Lambda pattern for delayed notifications.

πŸ—„οΈ Database Cold Start Optimization

Upgraded MySQL 8.0β†’8.4 LTS, migrated to Graviton2 (db.t4g), actively testing instance sizes to balance cold-start time vs running cost.

πŸ’‘ Technical Insights

  • Simplicity wins: Third-party APIs can be more reliable than complex AWS service integrations
  • Shell compatibility matters: Alpine Linux (ash) β‰  Ubuntu/Debian (bash)
  • IAM roles are distinct: Task execution role (infrastructure) vs task role (application permissions)
  • Idle detection requires calibration: Production testing essential for threshold tuning
  • Cloud dev environments: AWS CloudShell overcomes local system limitations
  • Cost optimization is architecture: 98% savings came from design, not tweaking

πŸŽ“ Learning Outcomes

This project demonstrates proficiency across backend development, cloud infrastructure, and DevOps practices:

Backend Development

Spring Boot 3.x, REST API design, JPA/Hibernate, Bean Validation, DTO patterns, global exception handling, comprehensive testing.

AWS Compute & Storage

ECS Fargate, RDS MySQL, ECR, S3, CloudFront. Hands-on deployment, configuration, and troubleshooting.

AWS Serverless

Lambda functions (Python/boto3), API Gateway, EventBridge scheduling, CloudWatch metrics analysis.

Cost Optimization

On-demand architecture, auto-shutdown systems, ALB elimination, resource right-sizing.

DevOps Practices

Docker multi-stage builds, CI/CD with CodeBuild, DNS automation, infrastructure monitoring, production debugging.

Problem Solving

400+ hours of iteration. Pivoted strategies when approaches failed. Made data-driven decisions based on production metrics.

▢️ Getting Started

Try the Live Demo

Click "Launch Music Library" at the top of this page. The app takes ~5-7 minutes to start, then auto-shuts down after 30 minutes of inactivity.

Run Locally

git clone https://github.com/jc-gh25/MusicLibrary.git
cd music-library && mvn spring-boot:run

Requires Java 17+, Maven 3.6+, and MySQL 8.0+. See GitHub README for full setup instructions.

Run Tests

mvn test

Runs unit and integration tests using H2 in-memory database. 600 automated tests, 100% pass rate.