How We Transformed a Legacy Contract System into Scalable Microservices

This article describes how a rapidly growing company refactored an outdated .NET contract management system into a set of independent microservices using the Stencil Ruby framework, detailing the motivations, microservice fundamentals, benefits, development workflow, deployment automation, and the resulting flexible architecture.

ITFLY8 Architecture Home
ITFLY8 Architecture Home
ITFLY8 Architecture Home
How We Transformed a Legacy Contract System into Scalable Microservices

Background and Challenges

As the company pursued international expansion and rapid domestic growth, the existing backend contract management system—built five years ago on .NET and tightly coupled to SAGE CRM—could no longer meet throughput, stability, and scalability requirements. Contract processing cost surged, taking about 3.5 person‑days per 100,000‑CNY contract.

To address these issues without interrupting business, the team defined a strategy:

Wrap core functionality of the legacy system with service interfaces.

Use the interfaces as proxies to decouple callers from the old system.

Gradually decompose the monolith into independent services.

Replace the legacy system entirely with newly built (micro)service interfaces.

What Is Microservice Architecture?

Microservices break a large application into small, independently deployable services. The approach is driven by domain‑driven design, agile practices, continuous delivery, infrastructure‑as‑code, and DevOps culture. Typical characteristics include:

Small, single‑purpose services (often a few hundred lines of code).

Each runs in its own process.

Lightweight, language‑agnostic communication (e.g., JSON, XML).

Loose coupling, allowing independent deployment.

Advantages of Microservices

Heterogeneity : Different services can use the most suitable technology stack, enabling safe experimentation and gradual adoption of new languages or frameworks.

Independent testing and deployment : Changes affect only the targeted service, reducing testing scope and deployment risk.

Fine‑grained scaling : Individual services can be scaled horizontally as needed.

Error isolation : Failures in one service do not bring down the entire system.

Team full‑stack ownership : Teams own the complete lifecycle of a service, aligning with Conway’s Law.

Rapid Microservice Development with Stencil

Stencil is a Ruby‑based framework that accelerates microservice creation. It consists of four parts:

Stencil templates : A Ruby library providing code and configuration templates. It uses Webmachine for the web framework, RESTful JSON communication, RSpec for testing, and defines Rake tasks for testing, packaging, and tagging RPMs. It also supplies common URLs for health checks and diagnostics.

Code generation tool : Generates a runnable microservice project with options such as name, Git owner, database inclusion, triggered tasks, provider/consumer roles, and branch selection. Example usage:

stencil new --name my-service --git-owner team --database --provider

Continuous integration template : Built on Bamboo, it defines three stages—packaging (run unit/integration tests and build RPM), publishing (push RPM to Koji, create AMI on AWS), and deployment (deploy AMI to test or production).

One‑click deployment tool : Uses Asgard on AWS to create, deploy, and switch traffic for services via a simple command:

asgard-deploy [AppName] [AppVersion]

New System Under Microservice Architecture

After five months, the contract management system was rebuilt as a collection of independent services handling product, pricing, sales, signing, review, and PDF generation. Each service has a dedicated owner and integrates with a notification system (Page Duty) for alerting. The UI layer became a lightweight front‑end that consumes these services, resulting in faster issue isolation and reduced defect‑fix cycles.

Conclusion

By adopting a microservice architecture and the Stencil framework, the team successfully decomposed a monolithic legacy system into loosely coupled, easily scalable services without disrupting ongoing business. The approach shortened development cycles, streamlined CI/CD, and provided the flexibility needed for future growth.

References

http://martinfowler.com/articles/microservices.html http://jaxenter.com/cracking-microservices-practices-50692.html http://microservices.io/patterns/microservices.html

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.

Software ArchitectureMicroservicescontinuous integrationcloud deploymentRubyLegacy Migration
ITFLY8 Architecture Home
Written by

ITFLY8 Architecture Home

ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.

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.