{"id":16076,"date":"2026-09-07T18:18:58","date_gmt":"2026-09-07T12:48:58","guid":{"rendered":"http:\/\/10.10.164.133\/?p=16076"},"modified":"2026-09-07T18:20:58","modified_gmt":"2026-09-07T12:50:58","slug":"agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform","status":"publish","type":"post","link":"https:\/\/payu.in\/blog\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/","title":{"rendered":"Agentic AI for Architectural Refactoring: How PayU Consolidated Its Distributed Bill-Payments Platform"},"content":{"rendered":" \n<h2 class=\"wp-block-heading\">Rethinking the Microservices Trade-off<\/h2>\n\n\n\n<p>Microservices are the industry standard for scale, and for good reason: independent domains, autonomous teams shipping on their own cadence, and clean bounded contexts justify the network hop many times over. Our BBPS platform runs on a dozen-odd services, and for most of them that separation still earns its keep &#8211; clean domain ownership, parallel development, independent release timelines.<\/p>\n\n\n\n<p>Three of those services were a different case. Together they powered a single offering &#8211; our bill-payments solution for banks &#8211; and they behaved as one logical unit: a shared release cadence, mostly maintenance mode with changes landing only occasionally, and inter-service calls that had thinned out to fetching a config or verifying an identifier. The boundaries between them had stopped buying anything, but they kept costing:<\/p>\n\n\n\n<ul>\n<li class=\"has-small-font-size\">Security patching, done in three places for one CVE (Common Vulnerabilities and Exposures)<\/li>\n\n\n\n<li class=\"has-small-font-size\">Alerting and dashboards, maintained for three services<\/li>\n\n\n\n<li class=\"has-small-font-size\">Runtime and dependency upgrades, shipped three times over<\/li>\n<\/ul>\n\n\n\n<p>Paid in every environment, on every change.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Goal: Consolidation Without Compromise<\/strong><\/h2>\n\n\n\n<p>The objective was to consolidate three independently deployed Spring Boot services into a single deployable application running on one JVM &#8211; reducing infrastructure and operational overhead while keeping existing integrations unchanged. This meant more than merging code: we had to unify Spring application contexts, resolve configuration and bean conflicts, and untangle dependencies without disrupting the platform.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Blueprint: Three Modules, One Deployable Unit<\/h2>\n\n\n\n<p>Before writing a single line of migration code, we defined a strict multi-module Maven architecture to ensure future separability. Instead of dumping all the code into one bucket, we structured the codebase into distinct layers:<\/p>\n\n\n\n<ul>\n<li class=\"has-small-font-size\"><strong>A Shared Infrastructure Core:<\/strong> A library containing unified configurations, security protocols, and cross-module interfaces.<\/li>\n\n\n\n<li class=\"has-small-font-size\"><strong>Isolated Domain Libraries:<\/strong> Separate modules for each business domain, ensuring business rules never bled across boundaries.<\/li>\n\n\n\n<li class=\"has-small-font-size\"><strong>A Bootable Wrapper:<\/strong> A single, lightweight application module responsible solely for wiring the domains together and booting the JVM.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"3120\" height=\"1160\" src=\"https:\/\/payu.in\/blog\/wp-content\/uploads\/2026\/09\/payu-architecture-before-generic.png\" alt=\"\" class=\"wp-image-16092\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"3120\" height=\"1160\" src=\"https:\/\/payu.in\/blog\/wp-content\/uploads\/2026\/09\/payu-architecture-after-generic.png\" alt=\"\" class=\"wp-image-16093\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Bringing AI to the Table<\/h2>\n\n\n\n<p>With the module structure settled, the work turned mechanical &#8211; and enormous. Merging ~35,000 lines by hand is repetitive, error-prone conflict resolution: exactly the work agents are good at, and exactly where an unsupervised agent does the most damage. So we spent our effort on the guardrails, not the typing.<\/p>\n\n\n\n<p>Two questions shaped them. What does an agent need to know that isn&#8217;t in the code? And what has to be true of every change before we accept it? Both answers lived in <code>Claude.md<\/code>, inherited by every agent rather than explained once and trusted to stick.<\/p>\n\n\n\n<p>&nbsp;<strong>Turning Constraints Into Rules<\/strong><\/p>\n\n\n\n<p>Four constraints were absolute, and one was an opportunity we took. All five became checks the Reviewer could enforce mechanically:<\/p>\n\n\n\n<ul>\n<li class=\"has-small-font-size\"><strong>Zero client-level changes<\/strong> \u2192 endpoint signatures, paths, and response shapes frozen; any diff touching a controller contract rejected outright.<\/li>\n\n\n\n<li class=\"has-small-font-size\"><strong>Strict data isolation<\/strong> \u2192 no cross-module repository imports; every transactional boundary bound explicitly to its own datasource.<\/li>\n\n\n\n<li class=\"has-small-font-size\"><strong>Seamless identity preservation<\/strong> \u2192 central identity configuration off-limits; resolution happens inside the application, per request.<\/li>\n\n\n\n<li class=\"has-small-font-size\"><strong>Future separability<\/strong> \u2192 dependency direction fixed: domains may depend on the shared core, never on each other.<\/li>\n\n\n\n<li class=\"has-small-font-size\"><strong>Upgraded tech stack<\/strong> \u2192 one Java LTS and Spring Boot version across every module, no per-module overrides.<\/li>\n<\/ul>\n\n\n\n<p><code>Claude.md<\/code> carried the other half too &#8211; what a diff can&#8217;t convey: package topology and naming conventions, the annotation and bean-wiring patterns we treat as canonical, the file tree each wave owned, and a standing rule to port behaviour verbatim rather than improve it. Refactoring mid-merge makes every regression ambiguous.<\/p>\n\n\n\n<p><strong>The Merge: One Loop, Three Stages<\/strong><\/p>\n\n\n\n<p>A change went through the same loop until it passed three gates: <strong>Write \u2192 Review \u2192 Verify<\/strong>. We made the process scalable by creating <strong>separate rule files for each service<\/strong>, so every agent operated against explicit, service-specific expectations rather than a single generic checklist.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Write &#8211; Service-Specific Rules Drive the Migration<\/strong><\/h4>\n\n\n\n<p>Created individual rule files for each service containing its migration requirements, conventions, dependencies, and constraints. The Developer Agent used these rules as the source of truth while generating migration code in controlled waves: Foundation, Source migration and then Bootstrap<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Review &#8211; Rules Become an Independent Quality Gate<\/strong><\/h4>\n\n\n\n<p><strong>Reviewer agent <\/strong>reviewed the implementation <strong>against the relevant service rule file and accept or reject change. <\/strong>The Developer Agent corrected the implementation and resubmitted it, creating a repeatable <strong>write \u2192 review \u2192 fix loop<\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. Verify &#8211; Prove Behaviour After Every Wave<\/strong><\/h4>\n\n\n\n<p>Generated a <strong>regression suite for each service<\/strong> using GenAI and were <strong>reviewed manually<\/strong> before being used as the verification gate. The suite was validated against all services before the merge process began and Tests ran <strong>after every migration wave<\/strong>, rather than only once at the end. Verification therefore provided the second independent bar that a code review cannot: <strong>the migrated service still behaves identically<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"3120\" height=\"1440\" src=\"https:\/\/payu.in\/blog\/wp-content\/uploads\/2026\/09\/payu-agent-loop.png\" alt=\"\" class=\"wp-image-16094\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Framework Collisions: When Independently Correct Code Stops Being Correct<\/h2>\n\n\n\n<p>Merging mature applications doesn&#8217;t break because either side was wrong. It breaks because designs that held perfectly in isolation stop holding once two systems share a runtime.<\/p>\n\n\n\n<ul>\n<li class=\"has-small-font-size\"><strong>Multi-Context Security Management:<\/strong> With three services registered as separate clients in our identity system, one application now had to resolve the correct security context per request. Building that resolver surfaced a cache keyed by realm alone &#8211; adequate when each service owned one resource per realm, insufficient once three shared a process. The Reviewer Agent identified the risk of <strong>cross-service security-context leakage<\/strong> and fixed by keying the cache by <strong>realm + resource<\/strong>.<\/li>\n\n\n\n<li class=\"has-small-font-size\"><strong>Event-Driven Circular Dependencies:<\/strong> One domain needed to trigger a workflow in another. To internalize that call without a circular Maven dependency, the Developer Agent replaced it with a Spring <code>ApplicationEvent<\/code> on <code>@TransactionalEventListener(phase = AFTER_COMMIT)<\/code> &#8211; to trigger the action only after a successful transaction and preserved <strong>fire-and-forget behaviour<\/strong> without compile-time coupling.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">The Takeaway: Determinism in an AI World<\/h2>\n\n\n\n<p>The merger was a resounding success. We maintained zero API contract changes, all while executing a massive architectural shift under the hood. We didn&#8217;t just merge code; we collapsed network boundaries, slashed infrastructure overhead, and forged a highly cohesive engine capable of powering the bill-payment ecosystem with unprecedented efficiency.<\/p>\n\n\n\n<p>Our biggest takeaway goes beyond just this migration. In today&#8217;s engineering landscape, we are increasingly abstracting design patterns and coding principles to AI. Because we cannot always be certain of exactly what an LLM will generate, we must create deterministic programs, systems, and processes to ensure the AI&#8217;s output aligns perfectly with our intent.<\/p>\n\n\n\n<p><strong>No AI-generated merge was accepted without rigorous human review.<\/strong> Agentic AI is an incredibly capable execution engine, but it requires a boring, well-defined architecture and strict HITL (human in the loop) guardrails to succeed.<\/p>\n ","protected":false},"excerpt":{"rendered":"<p> Rethinking the Microservices Trade-off Microservices are the industry standard for scale, and for good reason: independent domains, autonomous teams shipping on their own cadence, and clean bounded contexts justify the&#8230; <\/p>\n","protected":false},"author":84,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_cs_disable_global_cta_banner":false,"_cs_disable_global_sticky_cta":false,"_cs_sticky_cta_enabled":false,"_cs_sticky_cta":{"heading":"","description":"","buttons":[]}},"categories":[1232],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Agentic AI for Architectural Refactoring: How PayU Consolidated Its Distributed Bill-Payments Platform - PayU Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/payu.in\/blog\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Agentic AI for Architectural Refactoring: How PayU Consolidated Its Distributed Bill-Payments Platform - PayU Blog\" \/>\n<meta property=\"og:description\" content=\"Rethinking the Microservices Trade-off Microservices are the industry standard for scale, and for good reason: independent domains, autonomous teams shipping on their own cadence, and clean bounded contexts justify the...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/payu.in\/blog\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/\" \/>\n<meta property=\"og:site_name\" content=\"PayU Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/PayUind\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-07T12:48:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-09-07T12:50:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/payu.in\/blog\/wp-content\/uploads\/2026\/09\/payu-architecture-before-generic.png\" \/>\n<meta name=\"author\" content=\"Nikita Ekka\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@payuind\" \/>\n<meta name=\"twitter:site\" content=\"@payuind\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nikita Ekka\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/10.10.164.133\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/\",\"url\":\"http:\/\/10.10.164.133\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/\",\"name\":\"Agentic AI for Architectural Refactoring: How PayU Consolidated Its Distributed Bill-Payments Platform - PayU Blog\",\"isPartOf\":{\"@id\":\"https:\/\/payu.in\/blog\/#website\"},\"datePublished\":\"2026-09-07T12:48:58+00:00\",\"dateModified\":\"2026-09-07T12:50:58+00:00\",\"author\":{\"@id\":\"https:\/\/payu.in\/blog\/#\/schema\/person\/a20ce79fd4ff1edcb9e22b0b8b64d1d8\"},\"breadcrumb\":{\"@id\":\"http:\/\/10.10.164.133\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/10.10.164.133\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/10.10.164.133\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/payu.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Engineering Blogs\",\"item\":\"http:\/\/10.10.164.133\/category\/engineering-blogs\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Agentic AI for Architectural Refactoring: How PayU Consolidated Its Distributed Bill-Payments Platform\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/payu.in\/blog\/#website\",\"url\":\"https:\/\/payu.in\/blog\/\",\"name\":\"PayU Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/payu.in\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/payu.in\/blog\/#\/schema\/person\/a20ce79fd4ff1edcb9e22b0b8b64d1d8\",\"name\":\"Nikita Ekka\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/payu.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4448daa49886616547819223e7d11196?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4448daa49886616547819223e7d11196?s=96&d=mm&r=g\",\"caption\":\"Nikita Ekka\"},\"sameAs\":[\"http:\/\/payu.in\/blog\"],\"url\":\"https:\/\/payu.in\/blog\/author\/nikita-ekka\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Agentic AI for Architectural Refactoring: How PayU Consolidated Its Distributed Bill-Payments Platform - PayU Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/payu.in\/blog\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/","og_locale":"en_US","og_type":"article","og_title":"Agentic AI for Architectural Refactoring: How PayU Consolidated Its Distributed Bill-Payments Platform - PayU Blog","og_description":"Rethinking the Microservices Trade-off Microservices are the industry standard for scale, and for good reason: independent domains, autonomous teams shipping on their own cadence, and clean bounded contexts justify the...","og_url":"https:\/\/payu.in\/blog\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/","og_site_name":"PayU Blog","article_publisher":"https:\/\/www.facebook.com\/PayUind\/","article_published_time":"2026-09-07T12:48:58+00:00","article_modified_time":"2026-09-07T12:50:58+00:00","og_image":[{"url":"https:\/\/payu.in\/blog\/wp-content\/uploads\/2026\/09\/payu-architecture-before-generic.png"}],"author":"Nikita Ekka","twitter_card":"summary_large_image","twitter_creator":"@payuind","twitter_site":"@payuind","twitter_misc":{"Written by":"Nikita Ekka","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/10.10.164.133\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/","url":"http:\/\/10.10.164.133\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/","name":"Agentic AI for Architectural Refactoring: How PayU Consolidated Its Distributed Bill-Payments Platform - PayU Blog","isPartOf":{"@id":"https:\/\/payu.in\/blog\/#website"},"datePublished":"2026-09-07T12:48:58+00:00","dateModified":"2026-09-07T12:50:58+00:00","author":{"@id":"https:\/\/payu.in\/blog\/#\/schema\/person\/a20ce79fd4ff1edcb9e22b0b8b64d1d8"},"breadcrumb":{"@id":"http:\/\/10.10.164.133\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/10.10.164.133\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/10.10.164.133\/agentic-ai-for-architectural-refactoring-how-payu-consolidated-its-distributed-bill-payments-platform\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/payu.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Engineering Blogs","item":"http:\/\/10.10.164.133\/category\/engineering-blogs\/"},{"@type":"ListItem","position":3,"name":"Agentic AI for Architectural Refactoring: How PayU Consolidated Its Distributed Bill-Payments Platform"}]},{"@type":"WebSite","@id":"https:\/\/payu.in\/blog\/#website","url":"https:\/\/payu.in\/blog\/","name":"PayU Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/payu.in\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/payu.in\/blog\/#\/schema\/person\/a20ce79fd4ff1edcb9e22b0b8b64d1d8","name":"Nikita Ekka","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/payu.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4448daa49886616547819223e7d11196?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4448daa49886616547819223e7d11196?s=96&d=mm&r=g","caption":"Nikita Ekka"},"sameAs":["http:\/\/payu.in\/blog"],"url":"https:\/\/payu.in\/blog\/author\/nikita-ekka\/"}]}},"_links":{"self":[{"href":"https:\/\/payu.in\/blog\/wp-json\/wp\/v2\/posts\/16076"}],"collection":[{"href":"https:\/\/payu.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/payu.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/payu.in\/blog\/wp-json\/wp\/v2\/users\/84"}],"replies":[{"embeddable":true,"href":"https:\/\/payu.in\/blog\/wp-json\/wp\/v2\/comments?post=16076"}],"version-history":[{"count":3,"href":"https:\/\/payu.in\/blog\/wp-json\/wp\/v2\/posts\/16076\/revisions"}],"predecessor-version":[{"id":16096,"href":"https:\/\/payu.in\/blog\/wp-json\/wp\/v2\/posts\/16076\/revisions\/16096"}],"wp:attachment":[{"href":"https:\/\/payu.in\/blog\/wp-json\/wp\/v2\/media?parent=16076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/payu.in\/blog\/wp-json\/wp\/v2\/categories?post=16076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/payu.in\/blog\/wp-json\/wp\/v2\/tags?post=16076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}