Deploy Scalable E-Commerce Application on Azure with Spring Boot, Kafka, Okta, and ELK


This architecture diagram represents a high-level deployment of a Spring Boot-based eCommerce platform on Azure Cloud, incorporating microservices, authentication, logging, and monitoring.

Key Components:

1️⃣ Frontend (Angular)

  • Deployed on Azure App Service.
  • Uses Azure Front Door as a load balancer for routing user requests.
  • Routes API requests through Azure API Management.

2️⃣ Authentication (Okta)

  • Uses OAuth2 via Okta for authentication and securing APIs.
  • Ensures secure access to backend services.

3️⃣ Backend (Spring Boot Microservices)

  • Hosted on Azure Kubernetes Service (AKS) for scalability.
  • Handles business logic and API calls.
  • Consumes & publishes events via Kafka (Azure Event Hubs).

4️⃣ Data Storage

  • PostgreSQL (Azure DB) for structured data (e.g., orders, users).
  • MongoDB (Azure Cosmos DB) for NoSQL data (e.g., product catalogs).
  • Redis (Azure Cache) for caching to improve performance.

5️⃣ Monitoring & Logging

  • Prometheus & Grafana for performance monitoring.
  • Azure Monitor & Application Insights for system observability.
  • ELK Stack (Elasticsearch, Logstash, Kibana) for centralized logging and analytics.

This setup provides a scalable, secure, and cloud-native architecture for an eCommerce platform


This guide provides a complete end-to-end implementation of an eCommerce platform using:

Spring Boot Microservices (Java backend)
Angular (Frontend UI)
Okta OAuth2 (Authentication & Security)
Azure Kubernetes Service (AKS) (Scalability & Container Orchestration)
Kafka (Azure Event Hubs) (Event-driven communication)
PostgreSQL & MongoDB (Databases)
Redis (Azure Cache) (Performance & Caching)
ELK Stack & Prometheus (Monitoring & Logging)


1️⃣ Environment Setup

1.1 Install Required Tools

Ensure you have the following installed:



Java 17+
Maven
Docker
Kubernetes CLI (kubectl)
Helm (for Kubernetes)
Azure CLI


1.2 Set Up Azure Cloud Infrastructure

1️⃣ Login to Azure

az login

2️⃣ Create a Resource Group

az group create --name ecom-group --location eastus

3️⃣ Create an Azure Kubernetes Cluster (AKS)

az aks create --resource-group ecom-group --name ecom-aks --node-count 3 --generate-ssh-keys
az aks get-credentials --resource-group ecom-group --name ecom-aks

4️⃣ Create an Azure Container Registry (ACR)

az acr create --resource-group ecom-group --name ecomacr --sku Basic
az acr login --name ecomacr

2️⃣ Backend: Spring Boot Microservices Implementation

2.1 Microservices Structure

ecommerce-platform/ ├── auth-service/ # Authentication & Okta integration ├── product-service/ # Manages product catalog (MongoDB) ├── order-service/ # Handles orders (PostgreSQL) ├── inventory-service/ # Tracks stock (PostgreSQL) ├── notification-service/ # Handles emails & Kafka events ├── api-gateway/ # Central API Gateway (Spring Cloud Gateway) ├── docker/ # Docker & Kubernetes configs └── scripts/ # DevOps & deployment scripts

2.2 Implement Authentication (Spring Security + Okta OAuth2)

📌 Spring Security 6+ uses SecurityFilterChain instead of WebSecurityConfigurerAdapter.

1️⃣ Add Dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

2️⃣ Configure Okta in application.yml

okta:
  oauth2:
    issuer: https://your-okta-domain/oauth2/default
    client-id: your-client-id
    client-secret: your-client-secret

3️⃣ Security Configuration (SecurityConfig.java)

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests(auth -> auth
                .requestMatchers("/api/public/**").permitAll()
                .anyRequest().authenticated()
            )
            .oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt);
        return http.build();
    }
}

Replaces deprecated WebSecurityConfigurerAdapter.
Uses OAuth2 with Okta for JWT authentication.


2.3 Implement Product Service (MongoDB)

1️⃣ Add Dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

2️⃣ Define Product Model

@Document(collection = "products")
@Data
public class Product {
    @Id
    private String id;
    private String name;
    private Double price;
    private String category;
}

3️⃣ Create Repository

@Repository
public interface ProductRepository extends MongoRepository<Product, String> { }

2.4 Implement Order Service (PostgreSQL)

1️⃣ Add Dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
</dependency>

2️⃣ Define Order Model

@Entity
@Data
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String productId;
    private int quantity;
    private String userId;
    private String status;
}

2.5 Kafka Integration for Order Processing

1️⃣ Add Dependencies

<dependency>
    <groupId>org.springframework.kafka</groupId>
    <artifactId>spring-kafka</artifactId>
</dependency>

2️⃣ Publish Kafka Events

@Autowired
private KafkaTemplate<String, String> kafkaTemplate;

public void placeOrder(Order order) {
    orderRepository.save(order);
    kafkaTemplate.send("order-events", "New order placed: " + order.getId());
}

3️⃣ Monitoring & Logging (ELK + Prometheus)

3.1 Deploy ELK Stack on Azure

1️⃣ Install Elasticsearch, Logstash, and Kibana

helm repo add elastic https://helm.elastic.co
helm install elasticsearch elastic/elasticsearch
helm install kibana elastic/kibana

2️⃣ Configure Logstash

input {
  beats {
    port => 5044
  }
}
output {
  elasticsearch {
    hosts => ["http://elasticsearch:9200"]
  }
}

Aggregates logs from microservices into Kibana dashboards.


4️⃣ Deployment on Azure Kubernetes (AKS)

4.1 Dockerize Services

Each microservice has a Dockerfile:

FROM openjdk:17
COPY target/auth-service.jar auth-service.jar
ENTRYPOINT ["java", "-jar", "auth-service.jar"]

Build & Push:

docker build -t ecomacr.azurecr.io/auth-service:latest .
docker push ecomacr.azurecr.io/auth-service:latest

4.2 Deploy to Kubernetes (AKS)

1️⃣ Create Kubernetes Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: order-service
spec:
  replicas: 3
  selector:
    matchLabels:
      app: order-service
  template:
    metadata:
      labels:
        app: order-service
    spec:
      containers:
        - name: order-service
          image: ecomacr.azurecr.io/order-service:latest
          ports:
            - containerPort: 8080

Deploys to AKS with automatic scaling.

Popular posts from this blog

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Java, Spring Boot Mini Project - Library Management System - Download

ReactJS, Spring Boot JWT Authentication Example

Top 5 Java ORM tools - 2024

Java - Blowfish Encryption and decryption Example

Spring boot video streaming example-HTML5

Google Cloud Storage + Spring Boot - File Upload, Download, and Delete