Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver ToolsFeatured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver Tools

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Microservices Architecture Complete Guide

Microservices Architecture Complete Guide

Design and implement scalable microservices architectures with Google Antigravity

microservicesarchitecturedistributed-systemskafka
by antigravity-team
⭐0Stars
.antigravity
# Microservices Architecture Complete Guide for Google Antigravity

Build scalable, resilient microservices architectures using proven patterns optimized for Google Antigravity IDE development.

## Service Definition

```typescript
// services/user-service/src/index.ts
import Fastify from "fastify";
import { fastifySwagger } from "@fastify/swagger";
import { TypeBoxTypeProvider } from "@fastify/type-provider-typebox";
import { userRoutes } from "./routes/users";
import { healthRoutes } from "./routes/health";
import { setupTracing } from "./lib/tracing";
import { setupMetrics } from "./lib/metrics";

const buildServer = async () => {
  const app = Fastify({
    logger: {
      level: process.env.LOG_LEVEL || "info",
      transport: { target: "pino-pretty" }
    }
  }).withTypeProvider<TypeBoxTypeProvider>();

  // Setup observability
  await setupTracing(app);
  await setupMetrics(app);

  // Register plugins
  await app.register(fastifySwagger, {
    openapi: {
      info: { title: "User Service", version: "1.0.0" },
      servers: [{ url: process.env.SERVICE_URL }]
    }
  });

  // Register routes
  await app.register(healthRoutes, { prefix: "/health" });
  await app.register(userRoutes, { prefix: "/api/v1/users" });

  return app;
};

const start = async () => {
  const app = await buildServer();
  const port = parseInt(process.env.PORT || "3000");
  
  await app.listen({ port, host: "0.0.0.0" });
  console.log(`User service running on port ${port}`);
};

start().catch(console.error);
```

## Service Communication

```typescript
// lib/service-client.ts
import { createClient } from "@connectrpc/connect";
import { createGrpcTransport } from "@connectrpc/connect-node";
import { UserService } from "./gen/user/v1/user_connect";
import { CircuitBreaker } from "./circuit-breaker";

const circuitBreaker = new CircuitBreaker({
  failureThreshold: 5,
  resetTimeout: 30000,
  halfOpenRequests: 3
});

export const createUserServiceClient = (baseUrl: string) => {
  const transport = createGrpcTransport({
    baseUrl,
    httpVersion: "2",
    interceptors: [
      (next) => async (req) => {
        return circuitBreaker.execute(() => next(req));
      }
    ]
  });

  return createClient(UserService, transport);
};

// Event-driven communication
import { Kafka, Producer, Consumer } from "kafkajs";

export class EventBus {
  private kafka: Kafka;
  private producer: Producer;
  private consumers: Map<string, Consumer> = new Map();

  constructor(brokers: string[]) {
    this.kafka = new Kafka({ clientId: "user-service", brokers });
    this.producer = this.kafka.producer();
  }

  async publish<T>(topic: string, event: T): Promise<void> {
    await this.producer.send({
      topic,
      messages: [{ value: JSON.stringify(event), timestamp: Date.now().toString() }]
    });
  }

  async subscribe<T>(topic: string, handler: (event: T) => Promise<void>): Promise<void> {
    const consumer = this.kafka.consumer({ groupId: `${topic}-consumer` });
    await consumer.connect();
    await consumer.subscribe({ topic, fromBeginning: false });
    
    await consumer.run({
      eachMessage: async ({ message }) => {
        const event = JSON.parse(message.value?.toString() || "{}");
        await handler(event);
      }
    });
    
    this.consumers.set(topic, consumer);
  }
}
```

## Saga Pattern Implementation

```typescript
// lib/saga.ts
type SagaStep<T> = {
  name: string;
  execute: (context: T) => Promise<T>;
  compensate: (context: T) => Promise<T>;
};

export class SagaOrchestrator<T> {
  private steps: SagaStep<T>[] = [];
  private executedSteps: SagaStep<T>[] = [];

  addStep(step: SagaStep<T>): this {
    this.steps.push(step);
    return this;
  }

  async execute(initialContext: T): Promise<T> {
    let context = initialContext;
    
    for (const step of this.steps) {
      try {
        context = await step.execute(context);
        this.executedSteps.push(step);
      } catch (error) {
        await this.rollback(context);
        throw new SagaError(`Step ${step.name} failed`, error);
      }
    }
    
    return context;
  }

  private async rollback(context: T): Promise<void> {
    for (const step of [...this.executedSteps].reverse()) {
      try {
        await step.compensate(context);
      } catch (compensateError) {
        console.error(`Compensation failed for ${step.name}:`, compensateError);
      }
    }
  }
}
```

## Best Practices

1. **Single responsibility** per service with clear boundaries
2. **API versioning** for backward compatibility
3. **Circuit breakers** for fault tolerance
4. **Saga pattern** for distributed transactions
5. **Event sourcing** for audit trails and replay
6. **Service mesh** for traffic management
7. **Centralized logging** and distributed tracing

Google Antigravity provides intelligent assistance for designing service boundaries and implementing communication patterns effectively.

When to Use This Prompt

This microservices prompt is ideal for developers working on:

  • microservices applications requiring modern best practices and optimal performance
  • Projects that need production-ready microservices code with proper error handling
  • Teams looking to standardize their microservices development workflow
  • Developers wanting to learn industry-standard microservices patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their microservices implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the microservices code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this microservices prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For microservices projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...