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).
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" }
- If valid:
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?
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?
GET /valid-serials
- Returns all previously validated and stored serials in memory:
{ "serials": ["ABC1234567890XYZ", "ZXY9876543210ABC"] }
- Use Java 21+ and Spring Boot 3.x
- No database is required — use in-memory storage (e.g., a
ConcurrentHashMaporSet) - Use appropriate error handling and HTTP response codes
- The code should be self-contained and runnable with
mvn spring-boot:runor equivalent - Bonus: add simple tests with JUnit
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.
# 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# 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)# 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.
- 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.mdexplaining how to run the service and/or apply infra