Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Backend Development
5 min read

Microservice Architecture for One-Item-One-Code SaaS: .NET Core & 200K Codes in 26 Seconds

The article details the migration of a one-item-one-code SaaS platform from a monolithic architecture to a .NET Core-based microservice architecture, describing the design principles, core services (API gateway, security center, code management), data isolation, and achieving 200,000 code generations in 26 seconds with improved scalability and fault isolation.

Overview

As the one-item-one-code SaaS platform's business exploded, the traditional monolithic architecture faced severe challenges in feature iteration, high-concurrency code generation, and multi-end adaptation. This article analyzes the microservice architecture solution built on the cross-platform .NET Core technology stack. Through an API gateway, unified security center, and RPC communication mechanism, the system achieved module decoupling and supported a high-concurrency metric of generating 200,000 codes in 26 seconds (approximately 7,700 codes/second), providing a solid underlying engine for downstream subsystems such as anti-counterfeiting, anti-channel diversion, marketing, and traceability.

Business Pain Points of the Monolithic Architecture

Before the microservice transformation, the system used a traditional monolithic architecture that exposed three critical problems:

Highly coupled code, slow iteration: Traceability, marketing, anti-counterfeiting, and identification code management were all piled into a single project. Any minor bug fix required redeploying the entire system, posing huge downtime risk.

Performance bottlenecks and single points of failure: High-concurrency traffic from marketing activities (e.g., red packet grabs) often exhausted the database connection pool, dragging down the factory-side normal code issuance business.

Technology stack constraints: The massive monolithic application prevented development teams from selecting the most suitable technology framework for specific business modules or scaling independently.

Design Principles

To address the monolithic pain points, the team adopted a "large-grained decoupling, small-grained microservices" design philosophy, splitting the code platform into independent microservices:

Decomposition by business bounded contexts: Separated traceability, marketing, identification code management, anti-channel diversion, and other independent microservices.

Complete front-end/back-end separation: The front end uses a Vue-based SPA (Single Page Application) architecture to improve user experience; back-end microservices only output standard RESTful APIs.

Technology selection: Adopted .NET Core as the microservice development framework, leveraging its cross-platform, lightweight, and high-performance characteristics.

Figure 1: Microservice Architecture Core Functions Panorama
Figure 1: Microservice Architecture Core Functions Panorama

Overall Architecture Topology

The system architecture is divided into presentation layer, gateway layer, service layer, and data layer. All external requests (mobile, PC) enter uniformly through the API gateway. The gateway registers with the security center for unified identity verification and routing dispatch. Inter-service internal network calls use efficient RPC communication, while external access must carry security tokens.

Figure 2: Microservice Architecture Topology
Figure 2: Microservice Architecture Topology

Core Microservices

6.1 Unified Security Center & API Gateway

Internal Logic:

Security Center (SSO): Responsible for user single sign-on, identity authentication, and permission authorization. Legitimate clients are issued a Token.

API Gateway: Acts as the system's front door. All microservices register with the security center to become "protected resources." The gateway intercepts requests, validates token legitimacy, and simultaneously implements reverse proxy, load balancing, and request aggregation.

Internal/External Network Isolation: External requests access via gateway with tokens; frequent inter-service calls within the internal network use gRPC/RPC protocols, ensuring both security and efficiency.

Figure 3: Gateway Authentication & RPC Interaction Internal Logic
Figure 3: Gateway Authentication & RPC Interaction Internal Logic

6.2 Identification Code Management Microservice (Performance Breakthrough)

Internal Logic:

In the monolithic architecture, large-batch code issuance would lock the entire database table. After microservice decomposition, the identification code management service is deployed independently with its own dedicated database instance.

High code issuance capability: Through algorithm optimization and asynchronous task queues, the system achieved a remarkable 200,000 codes generated in 26 seconds (approx. 7,700 codes/second) performance breakthrough.

Multi-code support: Supports generation of multiple code types such as traceability codes and marketing codes, with format tools completing data conversion.

Figure 4: High-Concurrency Code Issuance Internal Logic
Figure 4: High-Concurrency Code Issuance Internal Logic

Data Model

The core principle of the microservice architecture is "data isolation." In this underlying architecture, each microservice accesses only its own dedicated database; direct cross-database join queries are not allowed.

Figure 5: Microservice Independent Data Model Association
Figure 5: Microservice Independent Data Model Association

Core Business Sequence Diagram

Using the client request "scan code and participate in marketing activity" as an example, the sequence diagram illustrates the highly available call chain under the microservice architecture.

Figure 6: Scan Code & Marketing Call Business Interaction Sequence Diagram
Figure 6: Scan Code & Marketing Call Business Interaction Sequence Diagram

Architectural Outcomes

Extreme performance and scalability: Broke through the monolithic bottleneck; microservices can be flexibly deployed according to traffic (e.g., the red packet service can be independently scaled to 10 servers), achieving high throughput.

High availability and fault isolation: If a non-core microservice (e.g., traceability) crashes, it will not bring down the entire system; core businesses like scan-code red packet issuance remain available.

Agile DevOps support: Supports CI/CD continuous deployment based on Docker containers; each microservice team can independently release updates, completely eliminating the "pull one hair and move the whole body" maintenance nightmare.

Flexible technology stack: Each microservice can flexibly choose .NET/C#, Java, or other languages according to actual needs, giving teams more freedom in technology selection.

Abbreviations

SaaS: Software as a Service

SPA: Single Page Application

RPC: Remote Procedure Call

API Gateway: API Gateway

SSO: Single Sign-On

CI/CD: Continuous Integration/Continuous Deployment

Code Platform: One-Item-One-Code SaaS Platform

For attribution, corrections or content rights, contactadmin@besthub.dev

Report an issue with this article

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion