Url shortener application with microservice architecture pattern
How to run all things • How to use • Projects • Roadmap • Error response
- Install docker and docker compose
docker-compose up --build
POST http://localhost:8080/api/v1/shortUrl
Content-Type: application/json
{
"longUrl" : "https://www.google.com"
}
HTTP/1.1 201
Content-Type: application/json
{
"shortUrl": "Ny1"
}
GET http://localhost:8080/api/v1/shortUrl/Ny1
HTTP/1.1 200
Redirections:
-> https://www.google.com/
- http://localhost:8080 - Api gateway
- http://localhost:8761 - Eureka dashboard
- http://localhost:8888 - Config server
- http://localhost:15672 - RabbitMq management (username/password: guest/guest)
- http://localhost:9090 - Prometheus
- http://localhost:3000 - Grafana (username/password: admin/password)
- http://localhost:9100 - Node exporter
- http://localhost:9411 - Zipkin
- http://localhost:5100 - Url shortener service
- http://localhost:27017 - MongoDB (username/password: rootuser/rootpass)
- http://localhost:8081 - Mongo express (username/password: rootuser/rootpass)
- http://localhost:6379 - Redis
- http://localhost:5200 - Range service
- http://localhost:3306 - Mysql (username/password/database: range_app/p_range_app/url_shortener)
- http://localhost:8082 - Jenkins
- Implemented Docker and Docker compose for deployment.
- Implemented unit testing and integration testing using JUnit, Mockito and Testcontainers.
- Implemented swagger documentation
- Improved the performance by implementing Redis caching in the application, resulting in faster response times.
- Utilized MongoDB as the database for the Url Shortener service, resulting in improved performance and scalability, as well as easier implementation of features such as sharding and replica sets.
- If one range service goes down, other instances will be tried by OpenFeign.
- Implemented url validation
- Swagger UI
- Utilized Pessimistic locking in JPA for the Range service to share range without concurrency problem for multiple instances of Url shortener service.
- Swagger UI
- Implemented Spring Cloud Config Server to store and manage configuration properties for multiple microservices.
- Spring Cloud Bus with RabbitMQ enables automatic reload of configuration changes across all instances of a microservice architecture, reducing downtime and increasing availability.
- Push commits in config repository
- Send request: POST http://localhost:8888/actuator/busrefresh
- Utilized Prometheus, Grafana, and Node exporter to monitor system performance and resource usage in real-time, allowing for proactive identification and resolution of potential issues.
- Implemented Zipkin for distributed tracing of microservices, helping to identify and diagnose performance issues within complex systems.
- Grafana setup:
- Add Prometheus data source with url http://host.docker.internal:9090
- Upload JSON file from observability/prometheus/grafana-dashboard.json
- Utilized the Spring Cloud API Gateway to effectively manage and route traffic across multiple microservices, resulting in improved performance and scalability of the overall system.
- Improved scalability and availability of services by using Eureka server for dynamic service discovery and load balancing.
- Jenkins pipeline
- Kubernetes
- ELK stack
- Mysql master slave replication
- Authentication and authorization
- Rate limiting with Spring Cloud Gateway
- AWS
POST /api/v1/shortUrl
Content-Type: application/json
{
"longUrl" : ""
}
HTTP/1.1 400
Content-Type: application/problem+json
{
"type": "about:blank",
"title": "ARGUMENT_VALIDATION_ERROR",
"status": 400,
"detail": "Url can not be empty",
"instance": "/api/v1/shortUrl"
}
POST /api/v1/shortUrl
Content-Type: application/json
{
"longUrl" : "ww.google"
}
HTTP/1.1 400
Content-Type: application/problem+json
{
"type": "about:blank",
"title": "ARGUMENT_VALIDATION_ERROR",
"status": 400,
"detail": "Invalid URL format found",
"instance": "/api/v1/shortUrl"
}
GET /api/v1/shortUrl/abcdef123456random
HTTP/1.1 404
Content-Type: application/json
{
"type": "about:blank",
"title": "NOT_FOUND",
"status": 404,
"detail": "Long url is not found",
"instance": "/api/v1/shortUrl/abcdef123456random"
}
Generic error response
HTTP/1.1 500
Content-Type: application/json
{
"type": "about:blank",
"title": "SYSTEM_ERROR",
"status": 500,
"detail": "The server encountered an error and could not complete your request. Please try again later.",
"instance": "/api/v1/shortUrl"
}
