Micro-Service Example with Tech-Ads: SpringBoot + Distributed Tracking + Circuit Breaker

Adtech is an important part of running a digital advertising campaign. Advertisers use adtech to buy, manage, and measure digital advertising. If you’re looking to get started with adtech, read on to learn about the adtech basics, including common tools and services, and the benefits of creating an advertising strategy that leverages adtech.

In the tutorial, I just log how to build a simple micro-service system for Ad-Tech.

Technologies

– SpringBoot
– Java 8
– Spring-Cloud: Sleuth
– Lombok
– Spring Aspect
– Open-Feign
– Spring Actuator
– Docker
– Kubernate K8s

Epic Architecture

Epic Architecture Design
Epic Architecture Design

1. Web-Parse Service: using to parse text from Web-URL

Web-Parse Service Project Structure
Web-Parse Service Project Structure

2. Ad-Tech Service: interact with Web-parse service and process to category a web-page.

Ad-Tech Service Project Structure
Ad-Tech Service Project Structure

Distributed Patterns

1. Distributed Tracking: using Spring Cloud Sleuth

Distributed Tracing with Spring Cloud Sleuth
Distributed Tracing with Spring Cloud Sleuth

2. Pattern Circuit Breaker – for cascading issue in distributed environments
In the Ad-Tech-Service, we use feign for calling API of Web-Parsing service with below configuration:

feign:
  client:
    config:
      default:
        connectTimeout: 20000
        readTimeout: 20000
        loggerLevel: BASIC

Web-Parse Service API

  /api/parse:
    post:
      summary: "POST api/parse"
      operationId: "parseWeb"
      responses:
        "200":
          description: "OK"
Web Parse Service API
Web Parse Service API

* Unit Testing:

Web-Parse Service Unit Test
Web-Parse Service Unit Test

Ad-Tech Service

  /api/categories:
    post:
      summary: "POST api/categories"
      operationId: "getUrlCategories"
      responses:
        "200":
          description: "OK"
Ad-Tech Service API
Ad-Tech Service API

* Unit Testing

Ad-Tech Service Unit-Testing
Ad-Tech Service Unit-Testing

Docker file

FROM adoptopenjdk:11-jre-hotspot
ARG JAR_FILE=*.jar
COPY ${JAR_FILE} application.jar
ENTRYPOINT ["java", "-jar", "application.jar"]

Kubernate Deployment + Service

1. Web-parse Service:
– Deployement:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: webparser
spec:
  replicas: 1
  selector:
    matchLabels:
      app: webparser
  template:
    metadata:
      labels:
        app: webparsers
    spec:
      containers:
        - name: app
          image: ozenero/web-parser:1.0.0
          ports:
            - containerPort: 9000
          imagePullPolicy: Always

– Service:

apiVersion: v1
kind: Service
metadata:
  name: webparser
spec:
  selector:
    app: webparser
  ports:
    - port: 9000
      targetPort: 9000
  type: ClusterIP

2. Ad-Tech Service:

– Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: adtech
spec:
  replicas: 1
  selector:
    matchLabels:
      app: adtech
  template:
    metadata:
      labels:
        app: adtech
    spec:
      containers:
        - name: app
          image: ozenero/ad-tech:1.0.0
          ports:
            - containerPort: 8080
          env:
            - name: WEB_PARSE_URL
              value: webparsers:9000/web-parser
          imagePullPolicy: Always

– Service:

apiVersion: v1
kind: Service
metadata:
  name: adtech
spec:
  selector:
    app: adtech
  ports:
    - port: 8080
      targetPort: 8080
  type: LoadBalancer

Why we use type: LoadBalancer for Ad-Service?
=> Because default is type: ClusterIP
We use type: LoadBalancer for public traffic-loading.

Note:

          env:
            - name: WEB_PARSE_URL
              value: webparsers:9000/web-parser

This is the url for feign calling from Ad-Tech service to Web-Parse service.

For kubectl-deployment, using cmd:

kubectl apply -f kube

For scaling, using cmd:

kubectl scale --replicas=2 deployment/webparser
kubectl scale --replicas=2 deployment/adtech

GitHub

– Ad-Tech Service
https://github.com/ozenero/ad-tech-service
– Web-Parse Service
https://github.com/ozenero/web-parser-service/

Amazon S3 – Upload/Download files with SpringBoot Amazon S3 application.

Amazon Simple Storage Service (Amazon S3) is object storage built to store and retrieve any amount of data from web or mobile. Amazon S3 is designed to scale computing easier for developers. For starting, in the tutorial, JavaSampleApproach show you how to create a SpringBoot Amazon S3 application.

Related post:
Amazon S3 – How to upload/download large files to S3 with SpringBoot Amazon S3 MultipartFile application

Continue reading “Amazon S3 – Upload/Download files with SpringBoot Amazon S3 application.”

How to create Client Load Balancing with Spring Cloud Ribbon + Spring Boot

In the tutorial, JavaSampleApproach will show you the steps of creating a Client Load Balancing with Spring Cloud Ribbon.

Related articles:
How to configure SpringBoot Zuul – Routing and Filtering
How to start with Spring Cloud Centralized Configuration

Continue reading “How to create Client Load Balancing with Spring Cloud Ribbon + Spring Boot”

How to configure SpringCloud Zuul – Routing and Filtering | SpringBoot

Netflix Zuul is a proxy solution to forward requests to microservices. In the tutorial, JavaSampleApproach will show you way to configure SpringBoot Zuul with routing & filtering.

Related articles:
Client Load Balancing with Spring Cloud Ribbon + Spring Boot
Spring Cloud Centralized Configuration

Continue reading “How to configure SpringCloud Zuul – Routing and Filtering | SpringBoot”

How to start with Spring Cloud Centralized Configuration

Spring Cloud provides an excellent mechanics to refresh all configured properties of a Spring Bean by @RefreshScope. So in the tutorial, JavaSampleApproach will introduce way to config Spring Cloud Centralized Configuration and the benifits of @RefreshScope.

Continue reading “How to start with Spring Cloud Centralized Configuration”