Loading repository dataβ¦
Loading repository dataβ¦
yashwalke999 / repository
π Build a Resilient e-Commerce Backend with Microservices π Explore a cutting-edge e-Commerce backend powered by microservices architecture. Enhance robustness and scalability without the clutter. Dive into modern principles of distributed systems, seamless communication, and secure API handling.
ClicknCart-backend-app [e-Commerce] --> Parent folder.
|- docs --> All docs and diagrams.
|- k8s --> All **Kubernetes** config files.
|- proxy-client --> Authentication & Authorization e-Commerce, exposing all
|- api-gateway --> API Gateway server
|- service-discovery --> Service Registery server
|- cloud-config --> Centralized Configuration server
|- user-service --> Manage app users (customers & admins) as well as their credentials
|- product-service --> Manage app products and their respective categories
|- favourite-service --> Manage app users' favourite products added to their own favourite list
|- order-service --> Manage app orders based on carts
|- shipping-service --> Manage app order-shipping products
|- payment-service --> Manage app order payments
|- compose.yml --> contains all services landscape with Kafka
|- run-em-all.sh --> Run all microservices in separate mode.
|- setup.sh --> Install all shared POMs and shared libraries.
|- stop-em-all.sh --> Stop all services runs in standalone mode.
|- test-em-all.sh --> This will start all docker compose landscape and test them, then shutdown docker compose containers with test finishes (use switch start stop)
Now, as we have learned about the different system components, let's get started.
Ensure you have the following software installed:
Java 11: JDK 11 LTS can be downloaded and installed from Oracle.
Git: Download and install from Git.
Maven: Download from Maven and install.
curl: Download and install from curl.
jq: Download and install from jq.
Spring Boot Initializer: Generate spring boot projects at Spring Initializer.
Docker: Download from Docker.
Kubernetes: Install minikube for testing purposes from Minikube.
Follow the installation guide for each software and verify that they are installed correctly.
I recommend using an IDE that supports the development of Spring Boot applications such as Spring Tool Suite or IntelliJ IDEA Ultimate Edition. Open or import the parent folder clickncart-microservice-backend-app in your IDE, and you're ready to go.
Open git bash and clone the project under your desired location:
> git clone https://github.com/yashwalke/clickncart-microservice-backend-app.git
### Build & Test Them In Isolation
To build and run the test cases for each service & shared modules in the project, we need to do the following:
#### Build & Test e-Commerces
Now it is the time to build our **10 microservices** and run each service integration test in
isolation by running the following commands:
```bash
yashw@:~/ClicknCart-backend-app$ ./mvnw clean package
All build commands and test suite for each microservice should run successfully, and the final output should be like this:
---------------< com.yashw.app:ecommerce-microservice-backend >-----------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for ecommerce-microservice-backend 0.1.0:
[INFO]
[INFO] ecommerce-microservice-backend ..................... SUCCESS [ 0.548 s]
[INFO] service-discovery .................................. SUCCESS [ 3.126 s]
[INFO] cloud-config ....................................... SUCCESS [ 1.595 s]
[INFO] api-gateway ........................................ SUCCESS [ 1.697 s]
[INFO] proxy-client ....................................... SUCCESS [ 3.632 s]
[INFO] user-service ....................................... SUCCESS [ 2.546 s]
[INFO] product-service .................................... SUCCESS [ 2.214 s]
[INFO] favourite-service .................................. SUCCESS [ 2.072 s]
[INFO] order-service ...................................... SUCCESS [ 2.241 s]
[INFO] shipping-service ................................... SUCCESS [ 2.197 s]
[INFO] payment-service .................................... SUCCESS [ 2.006 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.156 s
[INFO] Finished at: 2021-12-29T19:52:57+01:00
[INFO] ------------------------------------------------------------------------
Now it's the time to run all of our Microservices, and it's straightforward just run the following docker-compose commands:
yashw@:~/ClicknCart-backend-app$ docker-compose -f compose.yml up
All the services, databases, and messaging service will run in parallel in detach mode (option -d), and command output will print to the console the following:
Creating network "ClicknCart-backend-app_default" with the default driver
Creating ClicknCart-backend-app_api-gateway-container_1 ... done
Creating ClicknCart-backend-app_favourite-service-container_1 ... done
Creating ClicknCart-backend-app_service-discovery-container_1 ... done
Creating ClicknCart-backend-app_shipping-service-container_1 ... done
Creating ClicknCart-backend-app_order-service-container_1 ... done
Creating ClicknCart-backend-app_user-service-container_1 ... done
Creating ClicknCart-backend-app_payment-service-container_1 ... done
Creating ClicknCart-backend-app_product-service-container_1 ... done
Creating ClicknCart-backend-app_proxy-client-container_1 ... done
Creating ClicknCart-backend-app_zipkin-container_1 ... done
Creating ClicknCart-backend-app_cloud-config-container_1 ... done
You can manually test proxy-client APIs throughout its Swagger interface at the following
URL https://localhost:8900/swagger-ui.html.
If you would like to access the Eureka service discovery point to this URL http://localhosts:8761/eureka to see all the services registered inside it.
URL https://localhost:8700/swagger-ui.html.
The API Gateway and Store Service both act as a resource server.
{
"names": [
"http.server.requests",
"jvm.buffer.count",
"jvm.buffer.memory.used",
"jvm.buffer.total.capacity",
"jvm.classes.loaded",
"jvm.classes.unloaded",
"jvm.gc.live.data.size",
"jvm.gc.max.data.size",
"jvm.gc.memory.allocated",
"jvm.gc.memory.promoted",
"jvm.gc.pause",
"jvm.memory.committed",
"jvm.memory.max",
"jvm.memory.used",
"jvm.threads.daemon",
"jvm.threads.live",
"jvm.threads.peak",
"jvm.threads.states",
"logback.events",
"process.cpu.usage",
"process.files.max",
"process.files.open",
"process.start.time",
"process.uptime",
"resilience4j.circuitbreaker.buffered.calls",
"resilience4j.circuitbreaker.calls",
"resilience4j.circuitbreaker.failure.rate",
"resilience4j.circuitbreaker.not.permitted.calls",
"resilience4j.circuitbreaker.slow.call.rate",
"resilience4j.circuitbreaker.slow.calls",
"resilience4j.circuitbreaker.state",
"system.cpu.count",
"system.cpu.usage",
"system.load.average.1m",
"tomcat.sessions.active.current",
"tomcat.sessions.active.max",
"tomcat.sessions.alive.max",
"tomcat.sessions.created",
"tomcat.sessions.expired",
"tomcat.sessions.rejected",
"zipkin.reporter.messages",
"zipkin.reporter.messages.dropped",
"zipkin.reporter.messages.total",
"zipkin.reporter.queue.bytes",
"zipkin.reporter.queue.spans",
"zipkin.reporter.spans",
"zipkin.reporter.spans.dropped",
"zipkin.reporter.spans.total"
]
}
# HELP resilience4j_circuitbreaker_not_permitted_calls_total Total number of not permitted calls
# TYPE resilience4j_circuitbreaker_not_permitted_calls_total counter
resilience4j_circuitbreaker_not_permitted_calls_total{kind="not_permitted",name="proxyService",} 0.0
# HELP jvm_gc_live_data_size_bytes Size of long-lived heap memory pool after reclamation
# TYPE jvm_gc_live_data_size_bytes gauge
jvm_gc_live_data_size_bytes 3721880.0
# HELP jvm_gc_pause_seconds Time spent in GC pause
# TYPE jvm_gc_pause_seconds summary
jvm_gc_pause_seconds_count{action="end of minor GC",cause="Metadata GC Threshold",} 1.0
jvm_gc_pause_seconds_sum{action="end of minor GC",cause="Metadata GC Threshold",} 0.071
jvm_gc_pause_seconds_count{action="end of minor GC",cause="G1 Evacuation Pause",} 6.0
jvm_gc_pause_seconds_sum{action="end of minor GC",cause="G1 Evacuation Pause",} 0.551
# HELP jvm_gc_pause_seconds_max Time spent in GC pause
# TYPE jvm_gc_pause_seconds_max gauge
jvm_gc_pause_seconds_max{action="end of minor GC",cause="Metadata GC Threshold",} 0.071
jvm_gc_pause_seconds_max{action="end of minor GC",cause="G1 Evacuation Pause",} 0.136
# HELP system_cpu_usage The "recent cpu usage" for the whole system
# TYPE system_cpu_usage gauge
system_cpu_usage 0.4069206655413552
# HELP jvm_buffer_total_capacity_bytes An estimate of the total capacity of the buffers in this pool
# TYPE jvm_buffer_total_capacity_bytes gauge
jvm_buffer_total_capacity_bytes{id="mapped",} 0.0
jvm_buffer_total_capacity_bytes{id="direct",} 24576.0
# HELP zipkin_reporter_spans_dropped_total Spans dropped (failed to report)
# TYPE zipkin_reporter_spans_dropped_total counter
zipkin_reporter_spans_dropped_total 4.0
# HELP zipkin_reporter_spans_bytes_total Total bytes of encoded spans re