Skip to content

Instantly share code, notes, and snippets.

@fabio-t
Created July 23, 2025 16:57
Show Gist options
  • Save fabio-t/79cfeb23e1319e610f745f1d949ee0cb to your computer and use it in GitHub Desktop.
Save fabio-t/79cfeb23e1319e610f745f1d949ee0cb to your computer and use it in GitHub Desktop.
Exercise – RESTful Service with Spring Boot

📌 Objective

Create a Spring Boot microservice that exposes a REST API to validate and store product serial numbers, simulating an internal service that could be deployed in a microservice architecture (e.g., AWS Fargate or Kubernetes).


🛠 Requirements

✅ Endpoint

POST /validate-serial

  • Request body (JSON):

    {
      "serial": "string"
    }
  • Validation rules:

    • Serial must be exactly 16 characters.
    • Only alphanumeric characters.
    • Must start with a capital letter.
    • Must pass a dummy "checksum" rule: sum of character codes modulo 7 must be 0.
  • Response:

    • If valid:
      • 200 OK
      • Body:
        {
          "status": "VALID",
          "serial": "ABC1234567890XYZ"
        }
      • Also store the serial in memory.
    • If invalid:
      • 400 Bad Request
      • Body:
        {
          "status": "INVALID",
          "reason": "Checksum failed"
        }

💡 Caching Behaviour

Once a serial has been validated and stored in memory, it should act as a cache to avoid recalculating the validity for future requests of the same serial.

You may assume the service is stateless except for this cache, and a restart would clear it.

❓ In a real-world production system, what approach would you use to implement such a cache? What trade-offs would you consider?


📈 Concurrency & Scalability

This service should be designed to handle a high number of concurrent requests efficiently, as if it were deployed behind a public-facing endpoint. You are free to choose your preferred execution model — just ensure the service remains responsive and resource-efficient.

❓Optional discussion point: How would you configure the Spring Boot runtime to favour high concurrency and responsiveness without scaling vertically?


📥 Additional Endpoint

GET /valid-serials

  • Returns all previously validated and stored serials in memory:
    {
      "serials": ["ABC1234567890XYZ", "ZXY9876543210ABC"]
    }

⚙️ Technical Notes

  • Use Java 21+ and Spring Boot 3.x
  • No database is required — use in-memory storage (e.g., a ConcurrentHashMap or Set)
  • Use appropriate error handling and HTTP response codes
  • The code should be self-contained and runnable with mvn spring-boot:run or equivalent
  • Bonus: add simple tests with JUnit

🌍 Optional DevOps Task – Pick a Deployment Target

If you're comfortable with infrastructure-as-code or Kubernetes, you may complete one of the following scaffolds to simulate how this service would be deployed in the cloud. Feel free to modify or simplify.


📦 Option 1: Kubernetes (Manifests)

# deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: serial-validator
spec:
  replicas: 1
  selector:
    matchLabels:
      app: serial-validator
  template:
    metadata:
      labels:
        app: serial-validator
    spec:
      containers:
        - name: app
          image: <your-docker-image>
          ports:
            - containerPort: 8080

# service.yaml

apiVersion: v1
kind: Service
metadata:
  name: serial-validator
spec:
  selector:
    app: serial-validator
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: LoadBalancer

🚢 Option 2: AWS ECS on EC2 (Terraform Scaffold)

# main.tf

provider "aws" {
  region = "eu-central-1"
}

resource "aws_ecs_cluster" "main" {
  name = "serial-validator-cluster"
}

# TODO:
# - Define ECS Task Definition with your Docker image
# - Launch EC2-backed ECS service
# - Attach ALB (optional)

🛰 Option 3: AWS Fargate (Terraform Scaffold)

# main.tf

provider "aws" {
  region = "eu-central-1"
}

resource "aws_ecs_cluster" "main" {
  name = "serial-validator-fargate"
}

# TODO:
# - Create task definition for Fargate
# - Launch Fargate service in the cluster
# - Define VPC, subnet, security groups (or assume default)
# - (Optional) Add Application Load Balancer for external access

🔧 Even partial or incomplete files are fine — this is not a DevOps exam, but we’d love to understand your thinking.


💬 Submission Instructions

  • Submit a link to a public GitHub repository with:
    • Your Spring Boot project
    • Any optional Terraform/Kubernetes files (if you choose to do this)
    • A short README.md explaining how to run the service and/or apply infra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment