Monolith to Cloud-Native Microservices: The “Clere” Architecture Migration

    This article examines how the backend system code-named “Clere” evolved from a tightly coupled monolith into a cloud-native microservices architecture following a major business restructuring. It covers domain-driven service boundaries, message-based eventual consistency, container orchestration, canary releases, and observability, outlining a practical approach to incremental architectural change.

    Many software systems begin as monoliths because a single application makes it easier to validate a business model quickly. As the business grows and organizational structures change, however, tight coupling, difficult release cycles, and limited scalability can become obstacles.

    The backend system code-named “Clere” faced these challenges after a major restructuring that involved separating and reorganizing core business lines. Its migration illustrates how domain-driven design, asynchronous messaging, container orchestration, and controlled releases can support a gradual transition to cloud-native microservices.

    1. Domain-Driven Design: Redefining Boundaries and Extracting Services

    Clere began as a compact monolithic application, with all business logic maintained in a single codebase. As business complexity increased, changes in one area increasingly interfered with others. The team adopted domain-driven design (DDD) to guide service decomposition and establish clearer boundaries.

    The central task was identifying bounded contexts. By reviewing business workflows, the team separated previously intertwined capabilities—such as user management, order processing, and content distribution—into independent microservices. Each service had its own business boundary and data store, following the principle of high cohesion and loose coupling.

    • User context: Handles authentication and user profile management.
    • Transaction context: Manages order workflows and payment state machines.
    • Content context: Manages resource metadata and distribution policies.

    This separation reduced code complexity and allowed business teams to develop and release changes independently, improving delivery efficiency.

    2. Data Consistency: Managing Transactions Across Services

    Service decomposition introduced one of the migration’s most difficult challenges: maintaining data consistency across service boundaries. Operations previously covered by a local database transaction now required coordination between distributed services.

    To balance performance and consistency, the team chose message-based eventual consistency rather than two-phase commit (2PC). A reliable event pattern ensured that business changes and the recording of outgoing messages were atomic.

    The following pseudocode illustrates the approach:

    1. public void processOrder(Order order) {
    2. // 1. Save the order state within the local transaction.
    3. boolean saveSuccess = orderRepository.save(order);
    4. if (!saveSuccess) {
    5. throw new BusinessException("Failed to save order");
    6. }
    7. // 2. Create the event message.
    8. OrderCreatedEvent event = new OrderCreatedEvent(order.getId(), order.getUserId());
    9. // 3. Write the event to the local message table
    10. // within the same database transaction as the order update.
    11. messageRepository.saveLocalMessage(event);
    12. // 4. Deliver the message asynchronously to the message queue.
    13. // A scheduled background task scans the local message table
    14. // to ensure eventual delivery to the Baidu AI Cloud message queue service.
    15. }

    The critical requirement is that saving the order and writing the local message occur in the same database transaction. Message delivery then happens asynchronously.

    By combining a local message table with a message queue, Clere maintained eventual consistency after the business restructuring and reduced the risk of failures caused by isolated data or inconsistent states.

    3. Cloud-Native Infrastructure: Containerization and Resource Scheduling

    After decoupling the services, the team containerized Clere. Its previous virtual-machine-based deployment model suffered from low resource utilization and slow scaling, making it difficult to support rapid experimentation across new business lines.

    The team adopted a container orchestration platform, packaged the microservices as container images, and stored them in a reliable image registry. Declarative configuration defined replica counts, resource allocations, and scheduling policies.

    During traffic peaks, Horizontal Pod Autoscaling (HPA) could adjust the number of service replicas based on CPU and memory metrics, allocating resources according to demand.

    The system also needed to store large volumes of unstructured data. The team moved images, videos, and other static assets from application servers to an object storage service, further reducing application I/O pressure.

    4. Canary Releases: Controlling Traffic During the Transition

    During the early stages of refactoring and containerization, safely introducing new functionality into production became a key concern. Clere’s first canary release provided a controlled way to validate changes with limited exposure.

    The team introduced fine-grained traffic routing at the API gateway. Request attributes, such as a user ID hash, client version, or geographic tag, could determine whether a request reached the new service version. A small share of traffic—for example, 5%—could be routed to the canary while the remaining requests continued to use the stable version.

    The following illustrative Istio configuration combines header-based routing with a weighted traffic split:

    1. apiVersion: networking.istio.io/v1alpha3
    2. kind: VirtualService
    3. metadata:
    4. name: clere-order-service
    5. spec:
    6. hosts:
    7. - order-service
    8. http:
    9. - match:
    10. - headers:
    11. x-canary-flag:
    12. exact: "true"
    13. route:
    14. - destination:
    15. host: order-service
    16. subset: v2-canary
    17. weight: 100
    18. - route:
    19. - destination:
    20. host: order-service
    21. subset: v1-stable
    22. weight: 95
    23. - destination:
    24. host: order-service
    25. subset: v2-canary
    26. weight: 5

    Requests with the x-canary-flag header set to "true" are routed entirely to v2-canary. Other requests follow the weighted split: 95% to v1-stable and 5% to v2-canary.

    During the release, the team closely monitored error rates and response latency for the new version. If problems appeared, routing configuration could be changed to return traffic to the stable version, limiting the impact of the rollout.

    5. Observability: Keeping a Distributed System Operable

    Decoupling the application and moving to cloud-native infrastructure substantially increased the number of components. Troubleshooting through individual application logs was no longer sufficient.

    The team established an observability framework covering three areas:

    1. Centralized logging: Logs from all microservices were collected in a central logging service, supporting searches across multiple dimensions and alerting.
    2. Metrics and monitoring: A monitoring and alerting system collected container resource metrics, JVM runtime metrics, and custom business metrics. Dashboards provided a consolidated operational view.
    3. Distributed tracing: A unique trace ID was generated at the gateway and propagated between microservices. This allowed developers to reconstruct a request’s full call path and identify performance bottlenecks.

    Together, these capabilities made it easier to understand system behavior and investigate issues across service boundaries.

    Conclusion

    Clere’s transition from a monolith to cloud-native microservices was an iterative process of discovery and refactoring. DDD helped establish service boundaries, message-based eventual consistency addressed cross-service data coordination, container orchestration enabled demand-based resource allocation, and canary releases reduced deployment risk. Observability supported the operation of the resulting distributed system.

    These practices helped the system adapt to significant changes in business structure. They also offer a useful reference for teams facing similar migrations. No architecture is a silver bullet: sustained, incremental evolution remains essential as business requirements grow more complex.