Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use GitHub Copilot in VS Code to scaffold and refine a small service, but define the service boundary and state rules yourself: an instance should not be the only place a later request can find needed data. The example below uses a simple task-tracking API; its language, framework, database, and deployment platform are choices, not requirements. Treat Copilot’s output as a proposal, then review and validate it before relying on it.

What makes a microservice stateless?

A microservice should own a focused business capability, expose an explicit API, and manage its own data boundary. For this example, the capability is creating and retrieving tasks. A caller sends requests to a task API; the service stores durable task records in an external database or state service.

Statelessness is a runtime constraint, not a claim that the application has no data. A process instance may handle a request, but it must not be the only home of information needed by a later request. Instances can be replaced or scaled, so session details and durable records belong outside the instance. Microsoft’s microservices architecture guidance and AKS microservices reference architecture describe this approach.

Do not split an application into services merely by technical layer—for example, one service for database access and another for business logic. Choose a boundary around a cohesive business capability or bounded context. Every additional service introduces communication and coordination costs, so a small, well-defined service is more useful than a collection of tiny, loosely justified ones.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Define the service before asking Copilot to build it

Write down the responsibility, callers, data ownership, API contract, and failure behavior. A compact starting contract for the task service could be:

  • Responsibility: create and retrieve task records.
  • Callers: a user-facing application or another service.
  • Data ownership: the task service owns task records and their schema.
  • API: for example, POST /tasks to create a task and GET /tasks/{id} to retrieve one. Define request fields, response shape, validation, and error responses explicitly.
  • Persistence rule: save durable records in an external store; do not depend on in-memory collections or local files inside an instance for data that must survive replacement.

The endpoint names above are an illustrative contract, not a framework requirement. Choose the framework and database that fit the team and workload, then make those choices explicit in the repository instructions and prompt.

Prepare repository guidance in VS Code

Open the service repository in VS Code and add .github/copilot-instructions.md at the repository level. Use it to explain conventions that should apply throughout the project: the selected language and framework, the service boundary, persistence rules, security expectations, code style, and the commands used to validate changes.

For guidance that applies only to certain files, create a .instructions.md file with an applyTo pattern. For example, database-specific guidance can target migration or repository files without burdening unrelated code. VS Code documents both repository-wide and path-specific custom instructions in Use custom instructions in VS Code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Instruction discovery depends on the agent harness. VS Code says the Local agent also discovers the workspace instruction file when github.copilot.chat.codeGeneration.useInstructionFiles is enabled; support for custom instructions varies by harness. These files do not affect inline suggestions as you type, so do not assume a convention written there will govern every completion.

Use agent mode for a bounded implementation task

In VS Code, switch Copilot Chat to agent mode for a multi-step task such as implementing one endpoint and its tests. GitHub describes agent mode as able to determine which files to change, propose edits and terminal commands, and iterate to address problems. See Asking GitHub Copilot questions in your IDE.

Give it a bounded prompt that captures the decisions already made. For example:

Implement the task service’s POST /tasks endpoint using the repository’s selected framework. The service owns task records; persist them through the configured external database abstraction, not process memory or a local instance file. Validate the required fields, return the documented success and error responses, and add API and persistence tests. Do not add unrelated services or change the API contract. Run the validation commands in the repository instructions and report any failures.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Adapt the endpoint, contract, and validation commands to the actual project. A prompt is not a substitute for the repository’s architecture decisions, and a successful agent iteration does not prove that the code is correct. Review the proposed file changes and terminal commands before accepting or running them. VS Code also supports custom agents for reusable, specialized workflows; see Custom agents in VS Code.

Keep state outside replaceable service instances

When reviewing the implementation, trace a record from request to response and verify where it lives between requests. An in-memory map may work in a quick demonstration, but it is not durable across restarts and cannot reliably share state across multiple instances. A local database file inside a container has the same problem if the instance can be discarded without preserving that file.

Store durable data in an external database or state service and make the service responsible for its own data and schema. Keep transient request data local to the request where appropriate; do not rely on a particular process receiving the next request. If the API uses sessions, place the session state in an external store or use a design that does not require server-side session state.

Check the generated code for less obvious state coupling too: process-level caches that are treated as authoritative, background work that exists only in one instance’s memory, or startup logic that silently creates the only copy of required data. Such mechanisms may have valid uses, but they must not be mistaken for durable storage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the API, persistence, and failure paths

Use the test runner and commands chosen for the project; the exact commands depend on the selected stack. Validate behavior rather than merely checking that the application starts:

  • Test valid creation, field validation, retrieval, and the API’s documented error responses.
  • Test that a created record can be retrieved after the request that created it has ended, using the configured external store.
  • Where practical, restart or replace the service process and verify that previously saved records remain available.
  • Exercise database or dependency failures so the service returns a controlled error rather than an unexplained success or crash.
  • Run the project’s formatting, static analysis, and test commands, and inspect the generated dependency, configuration, and migration changes.

Read every change Copilot proposes, including infrastructure and terminal commands. Check authorization, input handling, secrets, schema changes, transaction boundaries, and error behavior against the application’s requirements. Passing the tests you have written is useful evidence, not a guarantee of production readiness.

Design health checks without creating a failure cascade

If the service will run under a container orchestrator, distinguish whether a probe answers “is this process alive?” from “should this instance receive traffic?” Configure health endpoints and probe behavior according to the platform’s semantics rather than treating every dependency problem as a process failure.

A readiness check that fails whenever an external dependency is briefly unavailable can mark every replica unready, remove the service from load balancing, and contribute to cascading failures. Microsoft discusses this risk in its AKS microservices reference architecture. Consider whether dependency retries, timeouts, and resilient error handling are more appropriate than taking all instances out of service during a temporary outage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Plan deployment and operations as a separate design decision

Independent deployment is one benefit of a microservice, but the service still has to be operated as part of a distributed system. Plan for monitoring, service-level validation, secure pipelines, and safe deployment practices alongside the boundary and API. Microsoft’s CI/CD guidance for microservices covers service-level validation and deployment practices.

Azure is one possible destination, not a requirement of using Copilot in VS Code. Microsoft documents a workflow in which GitHub Copilot for Azure agent mode helps create infrastructure files and a deployment template and invoke Azure Developer CLI tooling in its Azure deployment quickstart. Use that as a platform-specific option only if Azure fits your needs; choose hosting based on operational burden, infrastructure control, scaling, communication, rollout, and health-management requirements.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.