Cloud Native 19 min read

Master SaaS Multi‑Tenant Architecture: From Tech Stack to Cloud‑Native Deployment

This article walks developers through SaaS cloud‑native architecture, covering technology stack selection, multi‑tenant design at the application and data layers, microservice development with Spring Cloud and Huawei CSE, container deployment on CCE, and practical code examples from the SaaS‑Housekeeper project.

Huawei Cloud Developer Alliance
Huawei Cloud Developer Alliance
Huawei Cloud Developer Alliance
Master SaaS Multi‑Tenant Architecture: From Tech Stack to Cloud‑Native Deployment

Series Overview

Huawei Cloud Developer Alliance offers a technical open‑class series covering SaaS cloud‑native application architecture, design, and implementation.

Course Schedule

Episode 1: Typical SaaS cloud‑native architecture

Episode 2: SaaS application technical architecture design

Episode 3: SaaS data routing design and implementation

Episode 4: SaaS‑Housekeeper project practice

SaaS Technology Stack Selection

Four principles guide stack choice: introduce components as needed, use familiar mature technologies, anticipate 1‑2 years of growth, and consider cost‑effectiveness.

Multi‑Tenant Design

Application Layer

Four deployment modes on Huawei Cloud Container Engine (CCE) are discussed—Pod mode, Namespace mode, Cluster mode, and Network‑environment mode—each with its own advantages and drawbacks.

Data Layer

Three isolation strategies are presented: shared database with shared schema, shared database with schema isolation, and separate databases per tenant, together with their pros and cons.

Microservice Development

The solution uses Spring Boot, Spring Cloud, and Huawei Cloud Service Engine (CSE) to provide registration, governance, and configuration management, fully compatible with open‑source ecosystems.

Container Deployment

CCE delivers a Kubernetes‑based container service that offers high availability, elastic scaling, and resource‑utilization optimization.

Front‑End Tenant Routing

Two approaches are described: assigning a distinct domain to each tenant or using a unified domain with a tenant identifier passed as a request parameter.

Back‑End Tenant Routing

Tenant identifiers are propagated via gateways, thread‑local storage, Hystrix request variables, and are used to select appropriate data sources and schemas at runtime.

Code Example: Tenant Context

public class TenantContext {
    private static final HystrixRequestVariableDefault<Map<String, String>> TENANT_KEY =
            new HystrixRequestVariableDefault<>();

    public static String getDomain() {
        return Optional.ofNullable(TENANT_KEY.get()).orElse(new HashMap<>())
                .get(Constants.TENANT_DOMAIN);
    }

    public static void setDomain(String domain) {
        HystrixRequestContext.initializeContext();
        Map<String, String> variableMap = new HashMap<>(2);
        variableMap.put(Constants.TENANT_DOMAIN, domain);
        variableMap.put(Constants.DB_STRATEGY, Constants.DB_SLAVE);
        TENANT_KEY.set(variableMap);
    }
}

Configuration Examples

Dynamic routing can be refreshed using K8s ConfigMap mode or Spring Cloud Bus event mechanisms.

Project Practice

The SaaS‑Housekeeper project demonstrates a complete SaaS solution built with Java, Spring Cloud, CSE, CCE, RDS, Redis, and LTS, illustrating multi‑tenant routing, data‑source management, and customizable front‑end themes.

Further Resources

SaaS development kits: https://gitee.com/HuaweiCloudDeveloper/huaweicloud-saas-development-kits

Documentation: https://support.developer.huaweicloud.com/doc/zh-cn_topic_0000001321416345-0000001321416345

SaaS‑Housekeeper architecture diagram
SaaS‑Housekeeper architecture diagram
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaarchitectureKubernetesmulti-tenantSaaS
Huawei Cloud Developer Alliance
Written by

Huawei Cloud Developer Alliance

The Huawei Cloud Developer Alliance creates a tech sharing platform for developers and partners, gathering Huawei Cloud product knowledge, event updates, expert talks, and more. Together we continuously innovate to build the cloud foundation of an intelligent world.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.