{"id":495,"date":"2026-06-13T05:55:12","date_gmt":"2026-06-13T05:55:12","guid":{"rendered":"https:\/\/harshad-sonawane.com\/blog\/?p=495"},"modified":"2026-05-17T05:37:45","modified_gmt":"2026-05-17T05:37:45","slug":"how-to-build-federated-graphql-microservices-with-spring-boot","status":"publish","type":"post","link":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/","title":{"rendered":"How to Build Federated GraphQL Microservices with Spring Boot"},"content":{"rendered":"<p data-start=\"65\" data-end=\"401\">Modern microservice architectures often face a major challenge: managing APIs across multiple distributed services without creating tightly coupled systems. Traditional REST-based <a href=\"https:\/\/harshad-sonawane.com\/blog\/java-applications-edge-iot-architecture\/\">microservices<\/a> can quickly become difficult to maintain because frontend applications frequently need to call several services to assemble a single response.<\/p>\n<p data-start=\"403\" data-end=\"700\">Federated GraphQL solves this problem by allowing multiple independent GraphQL services to work together as a single unified API gateway. Combined with <span class=\"hover:entity-accent entity-underline inline cursor-pointer align-baseline\"><span class=\"whitespace-normal\"><a href=\"https:\/\/harshad-sonawane.com\/blog\/audit-logging-in-java-microservices-techniques-and-compliance-tips\/\">Spring Boot<\/a><\/span><\/span>, this architecture provides scalable, flexible, and developer-friendly APIs for modern <a href=\"https:\/\/harshad-sonawane.com\/blog\/eventual-consistency-distributed-java-systems\/\">distributed systems<\/a>.<\/p>\n<p data-start=\"702\" data-end=\"949\">In this blog, we will explore how federated GraphQL works, how to build federated microservices using Spring Boot, schema federation concepts, Apollo Gateway integration, service composition, security, observability, and production best practices.<\/p>\n<hr data-start=\"951\" data-end=\"954\" \/>\n<h1 data-section-id=\"1e4sd6f\" data-start=\"956\" data-end=\"989\">Understanding Federated GraphQL<\/h1>\n<p data-start=\"991\" data-end=\"1098\">GraphQL Federation is an architecture pattern where multiple GraphQL services contribute to a shared graph.<\/p>\n<p data-start=\"1100\" data-end=\"1216\">Instead of creating one massive monolithic GraphQL server, each microservice owns its own schema and business logic.<\/p>\n<p data-start=\"1218\" data-end=\"1230\">For example:<\/p>\n<ul data-start=\"1232\" data-end=\"1326\">\n<li data-section-id=\"1wgy96c\" data-start=\"1232\" data-end=\"1260\">User Service manages users<\/li>\n<li data-section-id=\"12xe31w\" data-start=\"1261\" data-end=\"1295\">Product Service manages products<\/li>\n<li data-section-id=\"1196tmc\" data-start=\"1296\" data-end=\"1326\">Order Service manages orders<\/li>\n<\/ul>\n<p data-start=\"1328\" data-end=\"1391\">A federation gateway combines all schemas into one unified API.<\/p>\n<p data-start=\"1393\" data-end=\"1503\">Clients communicate only with the gateway, while the gateway internally orchestrates requests across services.<\/p>\n<hr data-start=\"1505\" data-end=\"1508\" \/>\n<h1 data-section-id=\"1t0kb2u\" data-start=\"1510\" data-end=\"1563\">Why Traditional REST Microservices Become Difficult<\/h1>\n<p data-start=\"1565\" data-end=\"1588\">In large-scale systems:<\/p>\n<ul data-start=\"1590\" data-end=\"1789\">\n<li data-section-id=\"11qj727\" data-start=\"1590\" data-end=\"1630\">Frontends often call multiple services<\/li>\n<li data-section-id=\"1jo5kaj\" data-start=\"1631\" data-end=\"1676\">APIs become over-fetching or under-fetching<\/li>\n<li data-section-id=\"8u4mvn\" data-start=\"1677\" data-end=\"1709\">API versioning becomes painful<\/li>\n<li data-section-id=\"x0gkus\" data-start=\"1710\" data-end=\"1746\">Cross-service joins become complex<\/li>\n<li data-section-id=\"qfj5vj\" data-start=\"1747\" data-end=\"1789\">Network overhead increases significantly<\/li>\n<\/ul>\n<p data-start=\"1791\" data-end=\"1799\">Example:<\/p>\n<p data-start=\"1801\" data-end=\"1826\">To display an order page:<\/p>\n<ol data-start=\"1828\" data-end=\"1922\">\n<li data-section-id=\"1e52jqs\" data-start=\"1828\" data-end=\"1848\">Call User Service<\/li>\n<li data-section-id=\"sobajx\" data-start=\"1849\" data-end=\"1872\">Call Product Service<\/li>\n<li data-section-id=\"e8t4a1\" data-start=\"1873\" data-end=\"1894\">Call Order Service<\/li>\n<li data-section-id=\"nd77c\" data-start=\"1895\" data-end=\"1922\">Merge responses manually<\/li>\n<\/ol>\n<p data-start=\"1924\" data-end=\"1969\">Federated GraphQL eliminates this complexity.<\/p>\n<hr data-start=\"1971\" data-end=\"1974\" \/>\n<h1 data-section-id=\"12u0a47\" data-start=\"1976\" data-end=\"2008\">Benefits of GraphQL Federation<\/h1>\n<h2 data-section-id=\"sb9jx5\" data-start=\"2010\" data-end=\"2032\">Unified API Gateway<\/h2>\n<p data-start=\"2034\" data-end=\"2074\">Clients interact with a single endpoint.<\/p>\n<h2 data-section-id=\"x2p9fh\" data-start=\"2076\" data-end=\"2105\">Independent Team Ownership<\/h2>\n<p data-start=\"2107\" data-end=\"2150\">Each service owns its schema independently.<\/p>\n<h2 data-section-id=\"132stla\" data-start=\"2152\" data-end=\"2176\">Reduced Network Calls<\/h2>\n<p data-start=\"2178\" data-end=\"2218\">Single query retrieves distributed data.<\/p>\n<h2 data-section-id=\"1qsvurq\" data-start=\"2220\" data-end=\"2250\">Better Frontend Flexibility<\/h2>\n<p data-start=\"2252\" data-end=\"2289\">Clients request only required fields.<\/p>\n<h2 data-section-id=\"1sq7i1w\" data-start=\"2291\" data-end=\"2314\">Improved Scalability<\/h2>\n<p data-start=\"2316\" data-end=\"2345\">Services scale independently.<\/p>\n<h2 data-section-id=\"bsdlfw\" data-start=\"2347\" data-end=\"2368\">Schema Composition<\/h2>\n<p data-start=\"2370\" data-end=\"2411\">Schemas merge dynamically into one graph.<\/p>\n<hr data-start=\"2413\" data-end=\"2416\" \/>\n<h1 data-section-id=\"1hqlp2a\" data-start=\"2418\" data-end=\"2453\">High-Level Federated Architecture<\/h1>\n<p data-start=\"2455\" data-end=\"2505\">A typical federated GraphQL architecture includes:<\/p>\n<ol data-start=\"2507\" data-end=\"2637\">\n<li data-section-id=\"2ee0dv\" data-start=\"2507\" data-end=\"2525\">GraphQL Gateway<\/li>\n<li data-section-id=\"1ogydjj\" data-start=\"2526\" data-end=\"2546\">User Microservice<\/li>\n<li data-section-id=\"tytrzo\" data-start=\"2547\" data-end=\"2570\">Product Microservice<\/li>\n<li data-section-id=\"fgubbq\" data-start=\"2571\" data-end=\"2592\">Order Microservice<\/li>\n<li data-section-id=\"1ippti\" data-start=\"2593\" data-end=\"2612\">Service Registry<\/li>\n<li data-section-id=\"dpsa1k\" data-start=\"2613\" data-end=\"2637\">Distributed Databases<\/li>\n<\/ol>\n<p data-start=\"2639\" data-end=\"2659\">The gateway handles:<\/p>\n<ul data-start=\"2661\" data-end=\"2757\">\n<li data-section-id=\"l5w13z\" data-start=\"2661\" data-end=\"2677\">Query planning<\/li>\n<li data-section-id=\"n7gzdx\" data-start=\"2678\" data-end=\"2695\">Request routing<\/li>\n<li data-section-id=\"5hwjwo\" data-start=\"2696\" data-end=\"2714\">Schema stitching<\/li>\n<li data-section-id=\"1jh5sy0\" data-start=\"2715\" data-end=\"2731\">Authentication<\/li>\n<li data-section-id=\"776f5t\" data-start=\"2732\" data-end=\"2741\">Caching<\/li>\n<li data-section-id=\"f1p1nj\" data-start=\"2742\" data-end=\"2757\">Rate limiting<\/li>\n<\/ul>\n<hr data-start=\"2759\" data-end=\"2762\" \/>\n<h1 data-section-id=\"7qiefi\" data-start=\"2764\" data-end=\"2782\">Technology Stack<\/h1>\n<p data-start=\"2784\" data-end=\"2821\">For this implementation, we will use:<\/p>\n<ul data-start=\"2823\" data-end=\"3072\">\n<li data-section-id=\"2kc2rb\" data-start=\"2823\" data-end=\"2832\"><a href=\"https:\/\/harshad-sonawane.com\/blog\/reduce-cloud-costs-java-applications\/\">Java<\/a> 21<\/li>\n<li data-section-id=\"lyf7sl\" data-start=\"2833\" data-end=\"2872\"><span class=\"hover:entity-accent entity-underline inline cursor-pointer align-baseline\"><span class=\"whitespace-normal\">Spring Boot<\/span><\/span><\/li>\n<li data-section-id=\"kdc4a0\" data-start=\"2873\" data-end=\"2889\">Spring GraphQL<\/li>\n<li data-section-id=\"16vtg8p\" data-start=\"2890\" data-end=\"2897\">Maven<\/li>\n<li data-section-id=\"1gqonh4\" data-start=\"2898\" data-end=\"2948\"><span class=\"hover:entity-accent entity-underline inline cursor-pointer align-baseline\"><span class=\"whitespace-normal\">Apollo GraphOS<\/span><\/span> Federation<\/li>\n<li data-section-id=\"1etlrsl\" data-start=\"2949\" data-end=\"2988\"><span class=\"hover:entity-accent entity-underline inline cursor-pointer align-baseline\"><span class=\"whitespace-normal\">PostgreSQL<\/span><\/span><\/li>\n<li data-section-id=\"1u6gra4\" data-start=\"2989\" data-end=\"2997\">Docker<\/li>\n<li data-section-id=\"13adeo7\" data-start=\"2998\" data-end=\"3072\"><span class=\"hover:entity-accent entity-underline inline cursor-pointer align-baseline\"><span class=\"whitespace-normal\">Apache <a href=\"https:\/\/harshad-sonawane.com\/blog\/building-real-time-applications-java-architecture-frameworks\/\">Kafka<\/a><\/span><\/span> (optional for async communication)<\/li>\n<\/ul>\n<hr data-start=\"3074\" data-end=\"3077\" \/>\n<h1 data-section-id=\"1qrupis\" data-start=\"3079\" data-end=\"3103\">Microservice Structure<\/h1>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute end-1.5 top-1 z-2 md:end-2 md:top-1\"><\/div>\n<div class=\"relative\">\n<div class=\"pe-11 pt-3\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>graphql-federation<\/span>\r\n<span>\u2502<\/span>\r\n<span>\u251c\u2500\u2500 gateway-service<\/span>\r\n<span>\u251c\u2500\u2500 user-service<\/span>\r\n<span>\u251c\u2500\u2500 product-service<\/span>\r\n<span>\u2514\u2500\u2500 order-service<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p data-start=\"3226\" data-end=\"3270\">Each service exposes its own GraphQL schema.<\/p>\n<hr data-start=\"3272\" data-end=\"3275\" \/>\n<h1 data-section-id=\"7urq7y\" data-start=\"3277\" data-end=\"3317\">Setting Up Spring Boot GraphQL Service<\/h1>\n<h2 data-section-id=\"1o0f6m5\" data-start=\"3319\" data-end=\"3340\">Maven Dependencies<\/h2>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span class=\"\u037co\">&lt;dependencies&gt;<\/span>\r\n\r\n<span>    <\/span><span class=\"\u037co\">&lt;dependency&gt;<\/span>\r\n<span>        <\/span><span class=\"\u037co\">&lt;groupId&gt;<\/span><span>org.springframework.boot<\/span><span class=\"\u037co\">&lt;\/groupId&gt;<\/span>\r\n<span>        <\/span><span class=\"\u037co\">&lt;artifactId&gt;<\/span><span>spring-boot-starter-graphql<\/span><span class=\"\u037co\">&lt;\/artifactId&gt;<\/span>\r\n<span>    <\/span><span class=\"\u037co\">&lt;\/dependency&gt;<\/span>\r\n\r\n<span>    <\/span><span class=\"\u037co\">&lt;dependency&gt;<\/span>\r\n<span>        <\/span><span class=\"\u037co\">&lt;groupId&gt;<\/span><span>org.springframework.boot<\/span><span class=\"\u037co\">&lt;\/groupId&gt;<\/span>\r\n<span>        <\/span><span class=\"\u037co\">&lt;artifactId&gt;<\/span><span>spring-boot-starter-web<\/span><span class=\"\u037co\">&lt;\/artifactId&gt;<\/span>\r\n<span>    <\/span><span class=\"\u037co\">&lt;\/dependency&gt;<\/span>\r\n\r\n<span>    <\/span><span class=\"\u037co\">&lt;dependency&gt;<\/span>\r\n<span>        <\/span><span class=\"\u037co\">&lt;groupId&gt;<\/span><span>com.graphql-java<\/span><span class=\"\u037co\">&lt;\/groupId&gt;<\/span>\r\n<span>        <\/span><span class=\"\u037co\">&lt;artifactId&gt;<\/span><span>graphql-java-extended-scalars<\/span><span class=\"\u037co\">&lt;\/artifactId&gt;<\/span>\r\n<span>    <\/span><span class=\"\u037co\">&lt;\/dependency&gt;<\/span>\r\n\r\n<span class=\"\u037co\">&lt;\/dependencies&gt;<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"3835\" data-end=\"3838\" \/>\n<h1 data-section-id=\"5gyl6a\" data-start=\"3840\" data-end=\"3867\">Creating the User Service<\/h1>\n<h2 data-section-id=\"1l6uzdx\" data-start=\"3869\" data-end=\"3886\">GraphQL Schema<\/h2>\n<p data-start=\"3888\" data-end=\"3895\">Create:<\/p>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute end-1.5 top-1 z-2 md:end-2 md:top-1\"><\/div>\n<div class=\"relative\">\n<div class=\"pe-11 pt-3\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>src\/main\/resources\/graphql\/user.graphqls<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p data-start=\"3963\" data-end=\"3970\">Schema:<\/p>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>type User @key(fields: \"id\") {<\/span>\r\n\r\n<span>    id: ID!<\/span>\r\n<span>    name: String!<\/span>\r\n<span>    email: String!<\/span>\r\n<span>}<\/span>\r\n\r\n<span>type Query {<\/span>\r\n\r\n<span>    getUserById(id: ID!): User<\/span>\r\n<span>}<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p data-start=\"4131\" data-end=\"4179\">The <code data-start=\"4135\" data-end=\"4141\">@key<\/code> directive enables federation support.<\/p>\n<hr data-start=\"4181\" data-end=\"4184\" \/>\n<h1 data-section-id=\"1c0k0c\" data-start=\"4186\" data-end=\"4199\">User Entity<\/h1>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>@<\/span><span class=\"\u037cm\">Data<\/span>\r\n<span>@<\/span><span class=\"\u037cm\">AllArgsConstructor<\/span>\r\n<span>@<\/span><span class=\"\u037cm\">NoArgsConstructor<\/span>\r\n<span class=\"\u037cg\">public<\/span><span> <\/span><span class=\"\u037cg\">class<\/span><span> <\/span><span class=\"\u037cm\">User<\/span><span> {<\/span>\r\n\r\n<span>    <\/span><span class=\"\u037cg\">private<\/span><span> <\/span><span class=\"\u037cm\">String<\/span><span> <\/span><span class=\"\u037cm\">id<\/span><span>;<\/span>\r\n<span>    <\/span><span class=\"\u037cg\">private<\/span><span> <\/span><span class=\"\u037cm\">String<\/span><span> <\/span><span class=\"\u037cm\">name<\/span><span>;<\/span>\r\n<span>    <\/span><span class=\"\u037cg\">private<\/span><span> <\/span><span class=\"\u037cm\">String<\/span><span> <\/span><span class=\"\u037cm\">email<\/span><span>;<\/span>\r\n<span>}<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"4368\" data-end=\"4371\" \/>\n<h1 data-section-id=\"1do0zp7\" data-start=\"4373\" data-end=\"4394\">User Query Resolver<\/h1>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>@<\/span><span class=\"\u037cm\">Controller<\/span>\r\n<span class=\"\u037cg\">public<\/span><span> <\/span><span class=\"\u037cg\">class<\/span><span> <\/span><span class=\"\u037cm\">UserController<\/span><span> {<\/span>\r\n\r\n<span>    @<\/span><span class=\"\u037cm\">QueryMapping<\/span>\r\n<span>    <\/span><span class=\"\u037cg\">public<\/span><span> <\/span><span class=\"\u037cm\">User<\/span><span> <\/span><span class=\"\u037cm\">getUserById<\/span><span>(<\/span>\r\n<span>            @<\/span><span class=\"\u037cm\">Argument<\/span><span> <\/span><span class=\"\u037cm\">String<\/span><span> <\/span><span class=\"\u037cm\">id<\/span><span>) {<\/span>\r\n\r\n<span>        <\/span><span class=\"\u037cg\">return<\/span><span> <\/span><span class=\"\u037cg\">new<\/span><span> <\/span><span class=\"\u037cm\">User<\/span><span>(<\/span>\r\n<span>                <\/span><span class=\"\u037cm\">id<\/span><span>,<\/span>\r\n<span>                <\/span><span class=\"\u037ck\">\"Harshad\"<\/span><span>,<\/span>\r\n<span>                <\/span><span class=\"\u037ck\">\"harshad@example.com\"<\/span>\r\n<span>        );<\/span>\r\n<span>    }<\/span>\r\n<span>}<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"4676\" data-end=\"4679\" \/>\n<h1 data-section-id=\"1klaktt\" data-start=\"4681\" data-end=\"4707\">Creating Product Service<\/h1>\n<h2 data-section-id=\"1eobwov\" data-start=\"4709\" data-end=\"4726\">Product Schema<\/h2>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>type Product @key(fields: \"id\") {<\/span>\r\n\r\n<span>    id: ID!<\/span>\r\n<span>    name: String!<\/span>\r\n<span>    price: Float!<\/span>\r\n<span>}<\/span>\r\n\r\n<span>type Query {<\/span>\r\n\r\n<span>    getProductById(id: ID!): Product<\/span>\r\n<span>}<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"4895\" data-end=\"4898\" \/>\n<h1 data-section-id=\"61sokr\" data-start=\"4900\" data-end=\"4918\">Product Resolver<\/h1>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>@<\/span><span class=\"\u037cm\">Controller<\/span>\r\n<span class=\"\u037cg\">public<\/span><span> <\/span><span class=\"\u037cg\">class<\/span><span> <\/span><span class=\"\u037cm\">ProductController<\/span><span> {<\/span>\r\n\r\n<span>    @<\/span><span class=\"\u037cm\">QueryMapping<\/span>\r\n<span>    <\/span><span class=\"\u037cg\">public<\/span><span> <\/span><span class=\"\u037cm\">Product<\/span><span> <\/span><span class=\"\u037cm\">getProductById<\/span><span>(<\/span>\r\n<span>            @<\/span><span class=\"\u037cm\">Argument<\/span><span> <\/span><span class=\"\u037cm\">String<\/span><span> <\/span><span class=\"\u037cm\">id<\/span><span>) {<\/span>\r\n\r\n<span>        <\/span><span class=\"\u037cg\">return<\/span><span> <\/span><span class=\"\u037cg\">new<\/span><span> <\/span><span class=\"\u037cm\">Product<\/span><span>(<\/span>\r\n<span>                <\/span><span class=\"\u037cm\">id<\/span><span>,<\/span>\r\n<span>                <\/span><span class=\"\u037ck\">\"Mechanical Keyboard\"<\/span><span>,<\/span>\r\n<span>                <\/span><span class=\"\u037cj\">120.0<\/span>\r\n<span>        );<\/span>\r\n<span>    }<\/span>\r\n<span>}<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"5208\" data-end=\"5211\" \/>\n<h1 data-section-id=\"1ebl65w\" data-start=\"5213\" data-end=\"5237\">Creating Order Service<\/h1>\n<p data-start=\"5239\" data-end=\"5299\">The Order Service references both User and Product entities.<\/p>\n<h2 data-section-id=\"1ipz2ca\" data-start=\"5301\" data-end=\"5316\">Order Schema<\/h2>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>extend type User @key(fields: \"id\") {<\/span>\r\n\r\n<span>    id: ID! @external<\/span>\r\n<span>}<\/span>\r\n\r\n<span>extend type Product @key(fields: \"id\") {<\/span>\r\n\r\n<span>    id: ID! @external<\/span>\r\n<span>}<\/span>\r\n\r\n<span>type Order {<\/span>\r\n\r\n<span>    id: ID!<\/span>\r\n<span>    quantity: Int!<\/span>\r\n<span>    user: User<\/span>\r\n<span>    product: Product<\/span>\r\n<span>}<\/span>\r\n\r\n<span>type Query {<\/span>\r\n\r\n<span>    getOrders: [Order]<\/span>\r\n<span>}<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"5600\" data-end=\"5603\" \/>\n<h1 data-section-id=\"10w5rm6\" data-start=\"5605\" data-end=\"5621\">Order Resolver<\/h1>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>@<\/span><span class=\"\u037cm\">Controller<\/span>\r\n<span class=\"\u037cg\">public<\/span><span> <\/span><span class=\"\u037cg\">class<\/span><span> <\/span><span class=\"\u037cm\">OrderController<\/span><span> {<\/span>\r\n\r\n<span>    @<\/span><span class=\"\u037cm\">QueryMapping<\/span>\r\n<span>    <\/span><span class=\"\u037cg\">public<\/span><span> <\/span><span class=\"\u037cm\">List<\/span><span>&lt;<\/span><span class=\"\u037cm\">Order<\/span><span>&gt; <\/span><span class=\"\u037cm\">getOrders<\/span><span>() {<\/span>\r\n\r\n<span>        <\/span><span class=\"\u037cg\">return<\/span><span> <\/span><span class=\"\u037cm\">List<\/span><span class=\"\u037cg\">.<\/span><span class=\"\u037cm\">of<\/span><span>(<\/span>\r\n<span>                <\/span><span class=\"\u037cg\">new<\/span><span> <\/span><span class=\"\u037cm\">Order<\/span><span>(<\/span>\r\n<span>                        <\/span><span class=\"\u037ck\">\"ORD-1\"<\/span><span>,<\/span>\r\n<span>                        <\/span><span class=\"\u037cj\">2<\/span><span>,<\/span>\r\n<span>                        <\/span><span class=\"\u037cg\">new<\/span><span> <\/span><span class=\"\u037cm\">User<\/span><span>(<\/span><span class=\"\u037ck\">\"1\"<\/span><span>, <\/span><span class=\"\u037cj\">null<\/span><span>, <\/span><span class=\"\u037cj\">null<\/span><span>),<\/span>\r\n<span>                        <\/span><span class=\"\u037cg\">new<\/span><span> <\/span><span class=\"\u037cm\">Product<\/span><span>(<\/span><span class=\"\u037ck\">\"101\"<\/span><span>, <\/span><span class=\"\u037cj\">null<\/span><span>, <\/span><span class=\"\u037cj\">0<\/span><span>)<\/span>\r\n<span>                )<\/span>\r\n<span>        );<\/span>\r\n<span>    }<\/span>\r\n<span>}<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"5999\" data-end=\"6002\" \/>\n<h1 data-section-id=\"138bagh\" data-start=\"6004\" data-end=\"6042\">Setting Up Apollo Federation Gateway<\/h1>\n<p data-start=\"6044\" data-end=\"6091\">The gateway composes schemas from all services.<\/p>\n<h2 data-section-id=\"1ss2o8d\" data-start=\"6093\" data-end=\"6117\">Gateway Configuration<\/h2>\n<p data-start=\"6119\" data-end=\"6156\">Example using Node.js Apollo Gateway:<\/p>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span class=\"\u037cg\">const<\/span><span> { ApolloGateway } <\/span><span class=\"\u037cg\">=<\/span>\r\n<span>    <\/span><span class=\"\u037cm\">require<\/span><span>(<\/span><span class=\"\u037ck\">'@apollo\/gateway'<\/span><span>);<\/span>\r\n\r\n<span class=\"\u037cg\">const<\/span><span> <\/span><span class=\"\u037cm\">gateway<\/span><span> <\/span><span class=\"\u037cg\">=<\/span><span> <\/span><span class=\"\u037cg\">new<\/span><span> <\/span><span class=\"\u037cm\">ApolloGateway<\/span><span>({<\/span>\r\n\r\n<span>    serviceList: [<\/span>\r\n<span>        { name: <\/span><span class=\"\u037ck\">'users'<\/span><span>, url: <\/span><span class=\"\u037ck\">'http:\/\/localhost:8081\/graphql'<\/span><span> },<\/span>\r\n<span>        { name: <\/span><span class=\"\u037ck\">'products'<\/span><span>, url: <\/span><span class=\"\u037ck\">'http:\/\/localhost:8082\/graphql'<\/span><span> },<\/span>\r\n<span>        { name: <\/span><span class=\"\u037ck\">'orders'<\/span><span>, url: <\/span><span class=\"\u037ck\">'http:\/\/localhost:8083\/graphql'<\/span><span> }<\/span>\r\n<span>    ]<\/span>\r\n<span>});<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"6512\" data-end=\"6515\" \/>\n<h1 data-section-id=\"1b7s1w8\" data-start=\"6517\" data-end=\"6540\">Unified Query Example<\/h1>\n<p data-start=\"6542\" data-end=\"6566\">Clients can now execute:<\/p>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>query {<\/span>\r\n\r\n<span>    getOrders {<\/span>\r\n\r\n<span>        id<\/span>\r\n<span>        quantity<\/span>\r\n\r\n<span>        user {<\/span>\r\n<span>            name<\/span>\r\n<span>            email<\/span>\r\n<span>        }<\/span>\r\n\r\n<span>        product {<\/span>\r\n<span>            name<\/span>\r\n<span>            price<\/span>\r\n<span>        }<\/span>\r\n<span>    }<\/span>\r\n<span>}<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p data-start=\"6783\" data-end=\"6839\">The gateway automatically resolves data across services.<\/p>\n<hr data-start=\"6841\" data-end=\"6844\" \/>\n<h1 data-section-id=\"u62zuj\" data-start=\"6846\" data-end=\"6879\">How Federation Works Internally<\/h1>\n<p data-start=\"6881\" data-end=\"6897\">Federation uses:<\/p>\n<ul data-start=\"6899\" data-end=\"6980\">\n<li data-section-id=\"bgniff\" data-start=\"6899\" data-end=\"6918\">Entity references<\/li>\n<li data-section-id=\"l5w13z\" data-start=\"6919\" data-end=\"6935\">Query planning<\/li>\n<li data-section-id=\"17adixt\" data-start=\"6936\" data-end=\"6956\">Schema composition<\/li>\n<li data-section-id=\"1u3ot49\" data-start=\"6957\" data-end=\"6980\">Distributed execution<\/li>\n<\/ul>\n<p data-start=\"6982\" data-end=\"7034\">The gateway generates an execution plan dynamically.<\/p>\n<p data-start=\"7036\" data-end=\"7044\">Example:<\/p>\n<ol data-start=\"7046\" data-end=\"7147\">\n<li data-section-id=\"4ywgar\" data-start=\"7046\" data-end=\"7068\">Query Order Service<\/li>\n<li data-section-id=\"a89v8b\" data-start=\"7069\" data-end=\"7088\">Extract User IDs<\/li>\n<li data-section-id=\"1wc6ohx\" data-start=\"7089\" data-end=\"7107\">Fetch User data<\/li>\n<li data-section-id=\"d388uw\" data-start=\"7108\" data-end=\"7129\">Fetch Product data<\/li>\n<li data-section-id=\"ji3htx\" data-start=\"7130\" data-end=\"7147\">Merge response<\/li>\n<\/ol>\n<p data-start=\"7149\" data-end=\"7188\">This process is transparent to clients.<\/p>\n<hr data-start=\"7190\" data-end=\"7193\" \/>\n<h1 data-section-id=\"173fd3n\" data-start=\"7195\" data-end=\"7214\">Entity Resolution<\/h1>\n<p data-start=\"7216\" data-end=\"7253\">Federation requires entity resolvers.<\/p>\n<p data-start=\"7255\" data-end=\"7263\">Example:<\/p>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>@<\/span><span class=\"\u037cm\">SchemaMapping<\/span><span>(<\/span><span class=\"\u037cm\">typeName<\/span><span> <\/span><span class=\"\u037cg\">=<\/span><span> <\/span><span class=\"\u037ck\">\"User\"<\/span><span>)<\/span>\r\n<span class=\"\u037cg\">public<\/span><span> <\/span><span class=\"\u037cm\">User<\/span><span> <\/span><span class=\"\u037cm\">resolveUser<\/span><span>(<\/span><span class=\"\u037cm\">User<\/span><span> <\/span><span class=\"\u037cm\">userReference<\/span><span>) {<\/span>\r\n\r\n<span>    <\/span><span class=\"\u037cg\">return<\/span><span> <\/span><span class=\"\u037cm\">userService<\/span><span class=\"\u037cg\">.<\/span><span class=\"\u037cm\">findById<\/span><span>(<\/span>\r\n<span>            <\/span><span class=\"\u037cm\">userReference<\/span><span class=\"\u037cg\">.<\/span><span class=\"\u037cm\">getId<\/span><span>()<\/span>\r\n<span>    );<\/span>\r\n<span>}<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p data-start=\"7447\" data-end=\"7505\">This resolves partial entity references into full objects.<\/p>\n<hr data-start=\"7507\" data-end=\"7510\" \/>\n<h1 data-section-id=\"1h3ycqv\" data-start=\"7512\" data-end=\"7547\">Schema Composition Best Practices<\/h1>\n<h2 data-section-id=\"1rpwsd3\" data-start=\"7549\" data-end=\"7581\">Keep Services Domain-Oriented<\/h2>\n<p data-start=\"7583\" data-end=\"7627\">Each service should own one business domain.<\/p>\n<p data-start=\"7629\" data-end=\"7643\">Good examples:<\/p>\n<ul data-start=\"7645\" data-end=\"7701\">\n<li data-section-id=\"7z7l8f\" data-start=\"7645\" data-end=\"7664\">Inventory Service<\/li>\n<li data-section-id=\"1djk6a7\" data-start=\"7665\" data-end=\"7682\">Payment Service<\/li>\n<li data-section-id=\"16opd0n\" data-start=\"7683\" data-end=\"7701\">Shipping Service<\/li>\n<\/ul>\n<p data-start=\"7703\" data-end=\"7709\">Avoid:<\/p>\n<ul data-start=\"7711\" data-end=\"7745\">\n<li data-section-id=\"1l3ujbp\" data-start=\"7711\" data-end=\"7728\">Utility Service<\/li>\n<li data-section-id=\"1dq0nq0\" data-start=\"7729\" data-end=\"7745\">Common Service<\/li>\n<\/ul>\n<hr data-start=\"7747\" data-end=\"7750\" \/>\n<h1 data-section-id=\"10xpxv4\" data-start=\"7752\" data-end=\"7774\">Avoid Tight Coupling<\/h1>\n<p data-start=\"7776\" data-end=\"7821\">Services should expose only necessary fields.<\/p>\n<p data-start=\"7823\" data-end=\"7861\">Avoid deep cross-service dependencies.<\/p>\n<hr data-start=\"7863\" data-end=\"7866\" \/>\n<h1 data-section-id=\"efl8k7\" data-start=\"7868\" data-end=\"7903\">Use Consistent Naming Conventions<\/h1>\n<p data-start=\"7905\" data-end=\"7917\">Standardize:<\/p>\n<ul data-start=\"7919\" data-end=\"7980\">\n<li data-section-id=\"1pc2jjb\" data-start=\"7919\" data-end=\"7933\">Entity names<\/li>\n<li data-section-id=\"11nz7x2\" data-start=\"7934\" data-end=\"7947\">Query names<\/li>\n<li data-section-id=\"vr1r7x\" data-start=\"7948\" data-end=\"7964\">Mutation names<\/li>\n<li data-section-id=\"12nvr40\" data-start=\"7965\" data-end=\"7980\">Error formats<\/li>\n<\/ul>\n<hr data-start=\"7982\" data-end=\"7985\" \/>\n<h1 data-section-id=\"18kn9bv\" data-start=\"7987\" data-end=\"8016\">Authentication and Security<\/h1>\n<p data-start=\"8018\" data-end=\"8073\">Authentication is typically centralized at the gateway.<\/p>\n<p data-start=\"8075\" data-end=\"8093\">Common approaches:<\/p>\n<ul data-start=\"8095\" data-end=\"8149\">\n<li data-section-id=\"18etji9\" data-start=\"8095\" data-end=\"8115\">JWT authentication<\/li>\n<li data-section-id=\"1rrwjp9\" data-start=\"8116\" data-end=\"8124\"><a href=\"https:\/\/harshad-sonawane.com\/blog\/two-factor-authentication-java-applications\/\">OAuth2<\/a><\/li>\n<li data-section-id=\"wbrnqb\" data-start=\"8125\" data-end=\"8149\">API Gateway validation<\/li>\n<\/ul>\n<p data-start=\"8151\" data-end=\"8212\">The gateway forwards identity context to downstream services.<\/p>\n<hr data-start=\"8214\" data-end=\"8217\" \/>\n<h1 data-section-id=\"pgagrx\" data-start=\"8219\" data-end=\"8254\">Handling Distributed Transactions<\/h1>\n<p data-start=\"8256\" data-end=\"8340\">GraphQL federation does not solve distributed transaction consistency automatically.<\/p>\n<p data-start=\"8342\" data-end=\"8360\">Use patterns like:<\/p>\n<ul data-start=\"8362\" data-end=\"8433\">\n<li data-section-id=\"ndysb8\" data-start=\"8362\" data-end=\"8376\">Saga Pattern<\/li>\n<li data-section-id=\"oddux7\" data-start=\"8377\" data-end=\"8405\">Event-driven communication<\/li>\n<li data-section-id=\"8ab6x7\" data-start=\"8406\" data-end=\"8433\">Compensation transactions<\/li>\n<\/ul>\n<p data-start=\"8435\" data-end=\"8525\">For asynchronous workflows, combine federation with <span class=\"hover:entity-accent entity-underline inline cursor-pointer align-baseline\"><span class=\"whitespace-normal\">Apache Kafka<\/span><\/span>.<\/p>\n<hr data-start=\"8527\" data-end=\"8530\" \/>\n<h1 data-section-id=\"mxbem7\" data-start=\"8532\" data-end=\"8558\">Performance Optimization<\/h1>\n<h2 data-section-id=\"1qy4zr\" data-start=\"8560\" data-end=\"8577\">Use DataLoader<\/h2>\n<p data-start=\"8579\" data-end=\"8618\">DataLoader prevents N+1 query problems.<\/p>\n<p data-start=\"8620\" data-end=\"8639\">Without DataLoader:<\/p>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute end-1.5 top-1 z-2 md:end-2 md:top-1\"><\/div>\n<div class=\"relative\">\n<div class=\"pe-11 pt-3\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>100 orders = 100 user queries<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p data-start=\"8696\" data-end=\"8710\">With batching:<\/p>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute end-1.5 top-1 z-2 md:end-2 md:top-1\"><\/div>\n<div class=\"relative\">\n<div class=\"pe-11 pt-3\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>100 orders = 1 batched query<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"8766\" data-end=\"8769\" \/>\n<h1 data-section-id=\"7jq81w\" data-start=\"8771\" data-end=\"8793\">Enable Query Caching<\/h1>\n<p data-start=\"8795\" data-end=\"8801\">Cache:<\/p>\n<ul data-start=\"8803\" data-end=\"8876\">\n<li data-section-id=\"115yfbf\" data-start=\"8803\" data-end=\"8833\">Frequently requested queries<\/li>\n<li data-section-id=\"1wjn4rm\" data-start=\"8834\" data-end=\"8850\">Entity lookups<\/li>\n<li data-section-id=\"1o1t5he\" data-start=\"8851\" data-end=\"8876\">Gateway execution plans<\/li>\n<\/ul>\n<hr data-start=\"8878\" data-end=\"8881\" \/>\n<h1 data-section-id=\"1rgduql\" data-start=\"8883\" data-end=\"8907\">Limit Query Complexity<\/h1>\n<p data-start=\"8909\" data-end=\"8941\">Prevent malicious queries using:<\/p>\n<ul data-start=\"8943\" data-end=\"8997\">\n<li data-section-id=\"qjjz00\" data-start=\"8943\" data-end=\"8959\">Depth limiting<\/li>\n<li data-section-id=\"1r818fy\" data-start=\"8960\" data-end=\"8981\">Complexity analysis<\/li>\n<li data-section-id=\"f1p1nj\" data-start=\"8982\" data-end=\"8997\">Rate limiting<\/li>\n<\/ul>\n<hr data-start=\"8999\" data-end=\"9002\" \/>\n<h1 data-section-id=\"c3dupo\" data-start=\"9004\" data-end=\"9034\">Observability and Monitoring<\/h1>\n<p data-start=\"9036\" data-end=\"9080\">Federated systems require strong monitoring.<\/p>\n<p data-start=\"9082\" data-end=\"9100\">Important metrics:<\/p>\n<ul data-start=\"9102\" data-end=\"9209\">\n<li data-section-id=\"1sxsfxm\" data-start=\"9102\" data-end=\"9117\">Query latency<\/li>\n<li data-section-id=\"1e62up5\" data-start=\"9118\" data-end=\"9147\">Service dependency failures<\/li>\n<li data-section-id=\"16pv9g7\" data-start=\"9148\" data-end=\"9172\">Gateway execution time<\/li>\n<li data-section-id=\"1n0dj5i\" data-start=\"9173\" data-end=\"9195\">Resolver performance<\/li>\n<li data-section-id=\"zrx39d\" data-start=\"9196\" data-end=\"9209\">Error rates<\/li>\n<\/ul>\n<p data-start=\"9211\" data-end=\"9229\">Recommended tools:<\/p>\n<ul data-start=\"9231\" data-end=\"9350\">\n<li data-section-id=\"btvcid\" data-start=\"9231\" data-end=\"9270\"><span class=\"hover:entity-accent entity-underline inline cursor-pointer align-baseline\"><span class=\"whitespace-normal\"><a href=\"https:\/\/harshad-sonawane.com\/blog\/monitoring-java-applications-prometheus-grafana-kubernetes\/\">Prometheus<\/a><\/span><\/span><\/li>\n<li data-section-id=\"u21111\" data-start=\"9271\" data-end=\"9310\"><span class=\"hover:entity-accent entity-underline inline cursor-pointer align-baseline\"><span class=\"whitespace-normal\">Grafana<\/span><\/span><\/li>\n<li data-section-id=\"1j40yc5\" data-start=\"9311\" data-end=\"9350\"><span class=\"hover:entity-accent entity-underline inline cursor-pointer align-baseline\"><span class=\"whitespace-normal\">Jaeger<\/span><\/span><\/li>\n<\/ul>\n<hr data-start=\"9352\" data-end=\"9355\" \/>\n<h1 data-section-id=\"1j0df3j\" data-start=\"9357\" data-end=\"9379\">Dockerizing Services<\/h1>\n<h2 data-section-id=\"gge8v\" data-start=\"9381\" data-end=\"9402\">Dockerfile Example<\/h2>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span class=\"\u037cg\">FROM<\/span><span> eclipse-temurin:21<\/span>\r\n\r\n<span class=\"\u037cg\">COPY<\/span><span> target\/app.jar app.jar<\/span>\r\n\r\n<span class=\"\u037cg\">ENTRYPOINT<\/span><span> [<\/span><span class=\"\u037ck\">\"java\"<\/span><span>,<\/span><span class=\"\u037ck\">\"-jar\"<\/span><span>,<\/span><span class=\"\u037ck\">\"\/app.jar\"<\/span><span>]<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"9527\" data-end=\"9530\" \/>\n<h1 data-section-id=\"oaly67\" data-start=\"9532\" data-end=\"9561\">Running with Docker Compose<\/h1>\n<div class=\"relative w-full mt-4 mb-1\">\n<div class=\"\">\n<div class=\"relative\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"h-full min-h-0 min-w-0\">\n<div class=\"border border-token-border-light border-radius-3xl corner-superellipse\/1.1 rounded-3xl\">\n<div class=\"h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse\/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback\">\n<div class=\"pointer-events-none absolute inset-x-4 top-12 bottom-4\">\n<div class=\"pointer-events-none sticky z-40 shrink-0 z-1!\">\n<div class=\"sticky bg-token-border-light\"><\/div>\n<\/div>\n<\/div>\n<div class=\"relative\">\n<div class=\"\">\n<div class=\"relative z-0 flex max-w-full\">\n<div id=\"code-block-viewer\" dir=\"ltr\" class=\"q9tKkq_viewer cm-editor z-10 light:cm-light dark:cm-light flex h-full w-full flex-col items-stretch \u037cd \u037cr\">\n<div class=\"cm-scroller\">\n<pre class=\"cm-content q9tKkq_readonly m-0\"><code><span>version: <\/span><span class=\"\u037ck\">'3'<\/span>\r\n\r\n<span>services:<\/span>\r\n\r\n<span>  user-service:<\/span>\r\n<span>    build: .\/user-service<\/span>\r\n\r\n<span>  product-service:<\/span>\r\n<span>    build: .\/product-service<\/span>\r\n\r\n<span>  order-service:<\/span>\r\n<span>    build: .\/order-service<\/span>\r\n\r\n<span>  gateway:<\/span>\r\n<span>    build: .\/gateway-service<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"\">\n<div class=\"\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"9790\" data-end=\"9793\" \/>\n<h1 data-section-id=\"3thghn\" data-start=\"9795\" data-end=\"9814\">Common Challenges<\/h1>\n<h2 data-section-id=\"g7j1al\" data-start=\"9816\" data-end=\"9835\">Schema Evolution<\/h2>\n<p data-start=\"9837\" data-end=\"9883\">Changing shared entities can break federation.<\/p>\n<p data-start=\"9885\" data-end=\"9924\">Always maintain backward compatibility.<\/p>\n<hr data-start=\"9926\" data-end=\"9929\" \/>\n<h1 data-section-id=\"j8d0ow\" data-start=\"9931\" data-end=\"9951\">N+1 Query Problems<\/h1>\n<p data-start=\"9953\" data-end=\"10018\">Poor resolver implementation can create excessive database calls.<\/p>\n<p data-start=\"10020\" data-end=\"10046\">Use batching aggressively.<\/p>\n<hr data-start=\"10048\" data-end=\"10051\" \/>\n<h1 data-section-id=\"gxs2qy\" data-start=\"10053\" data-end=\"10074\">Gateway Bottlenecks<\/h1>\n<p data-start=\"10076\" data-end=\"10120\">The gateway can become a central bottleneck.<\/p>\n<p data-start=\"10122\" data-end=\"10156\">Scale horizontally when necessary.<\/p>\n<hr data-start=\"10158\" data-end=\"10161\" \/>\n<h1 data-section-id=\"staj6w\" data-start=\"10163\" data-end=\"10180\">Over-Federation<\/h1>\n<p data-start=\"10182\" data-end=\"10221\">Do not split services too aggressively.<\/p>\n<p data-start=\"10223\" data-end=\"10267\">Too many small services increase complexity.<\/p>\n<hr data-start=\"10269\" data-end=\"10272\" \/>\n<h1 data-section-id=\"13xwx4o\" data-start=\"10274\" data-end=\"10315\">When Should You Use GraphQL Federation?<\/h1>\n<p data-start=\"10317\" data-end=\"10342\">Federation is ideal when:<\/p>\n<ul data-start=\"10344\" data-end=\"10489\">\n<li data-section-id=\"1iq8mqz\" data-start=\"10344\" data-end=\"10369\">Multiple teams own APIs<\/li>\n<li data-section-id=\"z9z34a\" data-start=\"10370\" data-end=\"10402\">Frontend needs aggregated data<\/li>\n<li data-section-id=\"wv2pqz\" data-start=\"10403\" data-end=\"10424\">APIs evolve rapidly<\/li>\n<li data-section-id=\"ketraz\" data-start=\"10425\" data-end=\"10450\">Systems are distributed<\/li>\n<li data-section-id=\"15lr34r\" data-start=\"10451\" data-end=\"10489\">Independent deployments are required<\/li>\n<\/ul>\n<p data-start=\"10491\" data-end=\"10512\">Avoid federation for:<\/p>\n<ul data-start=\"10514\" data-end=\"10594\">\n<li data-section-id=\"1kgtgr5\" data-start=\"10514\" data-end=\"10540\">Small monolithic systems<\/li>\n<li data-section-id=\"1xsvmj3\" data-start=\"10541\" data-end=\"10567\">Simple CRUD applications<\/li>\n<li data-section-id=\"158r739\" data-start=\"10568\" data-end=\"10594\">Low-scale internal tools<\/li>\n<\/ul>\n<hr data-start=\"10596\" data-end=\"10599\" \/>\n<h1 data-section-id=\"d96wq5\" data-start=\"10601\" data-end=\"10628\">Production Best Practices<\/h1>\n<h2 data-section-id=\"z91mzc\" data-start=\"10630\" data-end=\"10657\">Maintain Schema Registry<\/h2>\n<p data-start=\"10659\" data-end=\"10691\">Track schema versions carefully.<\/p>\n<h2 data-section-id=\"17w6lnm\" data-start=\"10693\" data-end=\"10716\">Use Contract Testing<\/h2>\n<p data-start=\"10718\" data-end=\"10766\">Validate federation compatibility automatically.<\/p>\n<h2 data-section-id=\"p59xlj\" data-start=\"10768\" data-end=\"10799\">Monitor Resolver Performance<\/h2>\n<p data-start=\"10801\" data-end=\"10840\">Slow resolvers impact the entire graph.<\/p>\n<h2 data-section-id=\"1r9gc9l\" data-start=\"10842\" data-end=\"10867\">Apply Circuit Breakers<\/h2>\n<p data-start=\"10869\" data-end=\"10913\">Prevent cascading failures between services.<\/p>\n<h2 data-section-id=\"1k9dvao\" data-start=\"10915\" data-end=\"10936\">Use API Governance<\/h2>\n<p data-start=\"10938\" data-end=\"10982\">Maintain schema standards organization-wide.<\/p>\n<hr data-start=\"10984\" data-end=\"10987\" \/>\n<h1 data-section-id=\"1329ug4\" data-start=\"10989\" data-end=\"11005\">Final Thoughts<\/h1>\n<p data-start=\"11007\" data-end=\"11273\">Federated GraphQL enables organizations to build scalable, flexible, and independently deployable APIs without sacrificing developer experience. Combined with <span class=\"hover:entity-accent entity-underline inline cursor-pointer align-baseline\"><span class=\"whitespace-normal\">Spring Boot<\/span><\/span>, federation creates a powerful architecture for modern microservices.<\/p>\n<p data-start=\"11275\" data-end=\"11430\">While federation introduces operational complexity, it solves many API orchestration challenges that traditional REST architectures struggle with at scale.<\/p>\n<p data-start=\"11432\" data-end=\"11576\">The key to success lies in designing clear service boundaries, maintaining schema governance, and investing in observability from the beginning.<\/p>\n<p data-start=\"11578\" data-end=\"11765\">For enterprise-grade systems, GraphQL federation offers a future-ready API strategy that improves frontend agility, reduces network overhead, and enables scalable distributed development.<\/p>\n<p data-start=\"11578\" data-end=\"11765\">\n\n\n<p class=\"o-typing-delay-100ms ticss-27f7e3e9 wp-block-paragraph\"><o-anim-typing>&lt;> <strong>&#8220;Happy developing, one line at a time!&#8221;<\/strong> &lt;\/><\/o-anim-typing><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Modern microservice architectures often face a major challenge: managing APIs across multiple distributed services without creating tightly coupled systems. Traditional REST-based microservices can quickly become difficult to maintain because frontend applications frequently need to call several services to assemble a single response. Federated GraphQL solves this problem by allowing multiple [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":497,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"footnotes":"","jetpack_publicize_message":"GraphQL, Federation, Apollo Federation, Spring Boot, Java, Microservices, GraphQL Gateway, Distributed Systems, Backend Development, API Gateway, Spring GraphQL, Federated Architecture, GraphQL Microservices, Docker, Kafka, PostgreSQL, API Design, Scalable Systems, Enterprise Java, Software Architecture","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[113],"tags":[377,61,372,34,66,10,369,375,371,370,373,376,2,252,9,171,364,12,3,374],"class_list":["post-495","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-spring-boot-aws-microservices","tag-api-design","tag-api-gateway","tag-apollo-federation","tag-backend-development","tag-distributed-systems","tag-docker","tag-enterprise-java","tag-federated-architecture","tag-federation","tag-graphql","tag-graphql-gateway","tag-graphql-microservices","tag-java","tag-kafka","tag-microservices","tag-postgresql","tag-scalable-systems","tag-software-architecture","tag-spring-boot","tag-spring-graphql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Build Federated GraphQL Microservices with Spring Boot - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;<\/title>\n<meta name=\"description\" content=\"Learn how to build federated GraphQL microservices with Spring Boot and Apollo Federation. Explore schema federation, distributed GraphQL architecture, entity resolution, gateway setup, performance optimization, security, and production best practices.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Build Federated GraphQL Microservices with Spring Boot - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;\" \/>\n<meta property=\"og:description\" content=\"Learn how to build federated GraphQL microservices with Spring Boot and Apollo Federation. Explore schema federation, distributed GraphQL architecture, entity resolution, gateway setup, performance optimization, security, and production best practices.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/\" \/>\n<meta property=\"og:site_name\" content=\"&lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-13T05:55:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2026\/06\/ChatGPT-Image-May-16-2026-07_53_15-PM.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"HS\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"HS\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/\"},\"author\":{\"name\":\"HS\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#\\\/schema\\\/person\\\/d82781218ba30c34fa81b49e8393681e\"},\"headline\":\"How to Build Federated GraphQL Microservices with Spring Boot\",\"datePublished\":\"2026-06-13T05:55:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/\"},\"wordCount\":912,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#\\\/schema\\\/person\\\/d82781218ba30c34fa81b49e8393681e\"},\"image\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/ChatGPT-Image-May-16-2026-07_53_15-PM.png\",\"keywords\":[\"API Design\",\"API Gateway\",\"Apollo Federation\",\"Backend Development\",\"Distributed Systems\",\"Docker\",\"Enterprise Java\",\"Federated Architecture\",\"Federation\",\"GraphQL\",\"GraphQL Gateway\",\"GraphQL Microservices\",\"Java\",\"Kafka\",\"Microservices\",\"PostgreSQL\",\"Scalable Systems\",\"Software Architecture\",\"Spring Boot\",\"Spring GraphQL\"],\"articleSection\":[\"Java, Spring Boot, AWS, Microservices\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/\",\"url\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/\",\"name\":\"How to Build Federated GraphQL Microservices with Spring Boot - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\\\/&gt;\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/ChatGPT-Image-May-16-2026-07_53_15-PM.png\",\"datePublished\":\"2026-06-13T05:55:12+00:00\",\"description\":\"Learn how to build federated GraphQL microservices with Spring Boot and Apollo Federation. Explore schema federation, distributed GraphQL architecture, entity resolution, gateway setup, performance optimization, security, and production best practices.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/#primaryimage\",\"url\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/ChatGPT-Image-May-16-2026-07_53_15-PM.png\",\"contentUrl\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/ChatGPT-Image-May-16-2026-07_53_15-PM.png\",\"width\":1536,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/how-to-build-federated-graphql-microservices-with-spring-boot\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Build Federated GraphQL Microservices with Spring Boot\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/\",\"name\":\"Harshad's Dev Diary\",\"description\":\"HARSHAD&#039;s Dev Diary\",\"publisher\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#\\\/schema\\\/person\\\/d82781218ba30c34fa81b49e8393681e\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/#\\\/schema\\\/person\\\/d82781218ba30c34fa81b49e8393681e\",\"name\":\"HS\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/about.jpg\",\"url\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/about.jpg\",\"contentUrl\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/about.jpg\",\"width\":400,\"height\":400,\"caption\":\"HS\"},\"logo\":{\"@id\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/about.jpg\"},\"sameAs\":[\"https:\\\/\\\/harshad-sonawane.com\\\/blog\"],\"url\":\"https:\\\/\\\/harshad-sonawane.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Build Federated GraphQL Microservices with Spring Boot - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;","description":"Learn how to build federated GraphQL microservices with Spring Boot and Apollo Federation. Explore schema federation, distributed GraphQL architecture, entity resolution, gateway setup, performance optimization, security, and production best practices.","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:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/","og_locale":"en_US","og_type":"article","og_title":"How to Build Federated GraphQL Microservices with Spring Boot - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;","og_description":"Learn how to build federated GraphQL microservices with Spring Boot and Apollo Federation. Explore schema federation, distributed GraphQL architecture, entity resolution, gateway setup, performance optimization, security, and production best practices.","og_url":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/","og_site_name":"&lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;","article_published_time":"2026-06-13T05:55:12+00:00","og_image":[{"width":1536,"height":1024,"url":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2026\/06\/ChatGPT-Image-May-16-2026-07_53_15-PM.png","type":"image\/png"}],"author":"HS","twitter_card":"summary_large_image","twitter_misc":{"Written by":"HS","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/#article","isPartOf":{"@id":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/"},"author":{"name":"HS","@id":"https:\/\/harshad-sonawane.com\/blog\/#\/schema\/person\/d82781218ba30c34fa81b49e8393681e"},"headline":"How to Build Federated GraphQL Microservices with Spring Boot","datePublished":"2026-06-13T05:55:12+00:00","mainEntityOfPage":{"@id":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/"},"wordCount":912,"commentCount":0,"publisher":{"@id":"https:\/\/harshad-sonawane.com\/blog\/#\/schema\/person\/d82781218ba30c34fa81b49e8393681e"},"image":{"@id":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/#primaryimage"},"thumbnailUrl":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2026\/06\/ChatGPT-Image-May-16-2026-07_53_15-PM.png","keywords":["API Design","API Gateway","Apollo Federation","Backend Development","Distributed Systems","Docker","Enterprise Java","Federated Architecture","Federation","GraphQL","GraphQL Gateway","GraphQL Microservices","Java","Kafka","Microservices","PostgreSQL","Scalable Systems","Software Architecture","Spring Boot","Spring GraphQL"],"articleSection":["Java, Spring Boot, AWS, Microservices"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/","url":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/","name":"How to Build Federated GraphQL Microservices with Spring Boot - &lt;&gt;HARSHAD&#039;s Dev Diary&lt;\/&gt;","isPartOf":{"@id":"https:\/\/harshad-sonawane.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/#primaryimage"},"image":{"@id":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/#primaryimage"},"thumbnailUrl":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2026\/06\/ChatGPT-Image-May-16-2026-07_53_15-PM.png","datePublished":"2026-06-13T05:55:12+00:00","description":"Learn how to build federated GraphQL microservices with Spring Boot and Apollo Federation. Explore schema federation, distributed GraphQL architecture, entity resolution, gateway setup, performance optimization, security, and production best practices.","breadcrumb":{"@id":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/#primaryimage","url":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2026\/06\/ChatGPT-Image-May-16-2026-07_53_15-PM.png","contentUrl":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2026\/06\/ChatGPT-Image-May-16-2026-07_53_15-PM.png","width":1536,"height":1024},{"@type":"BreadcrumbList","@id":"https:\/\/harshad-sonawane.com\/blog\/how-to-build-federated-graphql-microservices-with-spring-boot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/harshad-sonawane.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Build Federated GraphQL Microservices with Spring Boot"}]},{"@type":"WebSite","@id":"https:\/\/harshad-sonawane.com\/blog\/#website","url":"https:\/\/harshad-sonawane.com\/blog\/","name":"Harshad's Dev Diary","description":"HARSHAD&#039;s Dev Diary","publisher":{"@id":"https:\/\/harshad-sonawane.com\/blog\/#\/schema\/person\/d82781218ba30c34fa81b49e8393681e"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/harshad-sonawane.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/harshad-sonawane.com\/blog\/#\/schema\/person\/d82781218ba30c34fa81b49e8393681e","name":"HS","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/02\/about.jpg","url":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/02\/about.jpg","contentUrl":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/02\/about.jpg","width":400,"height":400,"caption":"HS"},"logo":{"@id":"https:\/\/harshad-sonawane.com\/blog\/wp-content\/uploads\/2025\/02\/about.jpg"},"sameAs":["https:\/\/harshad-sonawane.com\/blog"],"url":"https:\/\/harshad-sonawane.com\/blog\/author\/admin\/"}]}},"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/posts\/495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/comments?post=495"}],"version-history":[{"count":4,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/posts\/495\/revisions"}],"predecessor-version":[{"id":522,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/posts\/495\/revisions\/522"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/media\/497"}],"wp:attachment":[{"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/media?parent=495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/categories?post=495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/harshad-sonawane.com\/blog\/wp-json\/wp\/v2\/tags?post=495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}