Architecture principles
An architecture principle is a strong, reusable opinion on how something should be structured and designed — a guideline for how to architect, not the implementation detail of any one service. This page covers how Luna is put together as a set of microservices, the anatomy of a single service, the flavours a service can take, and the principles every service is expected to follow.
More detail and visuals
This page is the written reference. For the fuller picture — architecture diagrams, component maps, and worked examples — see the Luna architecture Miro board.
Microservices at Luna
Luna is a collection of decoupled microservices, each owning a slice of the business domain (engagements, expenses, auth, and so on). A microservice is an architectural pattern that decomposes business functionality into independent, loosely-coupled applications, and each Luna service is the source of truth for its own data — no service reaches into another's database directly.
Services communicate in two ways:
- Asynchronously — via SNS topics and SQS queues.
- Synchronously — over HTTP, through a shared API Gateway (or a local one where a service needs different or no auth).

Anatomy of a microservice
A service is composed of specialised components following a separation of concerns. It contains only the components it needs, and at most one Lambda per type — one subscriber, one querier, and so on. Data stores, buckets, and topics are the exception: a service can have several of each.

| Component | How many per service |
|---|---|
| Local API Gateway | One — only if the service has external/public endpoints |
| Lambda | One per type (e.g. one subscriber, one querier) |
| SQS queue | One |
| Dead-letter queue (DLQ) | One per queue |
| SNS topic | Multiple (or none) |
| DynamoDB table | Multiple (prefer one where possible) |
| S3 bucket | Multiple (or none) |
API Gateway
The API Gateway authenticates incoming requests and exposes client endpoints, integrating them to the Lambdas that handle them. There are two kinds:
- Shared API Gateway — for internal API endpoints that authenticate with OKTA. Services import the shared gateway and its Cognito JWT authorizer rather than defining their own.
- Local API Gateway — for external or public endpoints, where requests need different authentication (or none at all).
Lambdas
Luna services follow CQRS — responsibilities are split, with one Lambda per responsibility. Each Lambda type has a single, well-defined job:
| Lambda | Trigger | Responsibility |
|---|---|---|
| Gateway | External/public API Gateway | Handles external endpoints — authorizes the request (an authenticated caller still must be allowed to act), validates it (usually schema validation), and transforms it into Luna's model |
| Commands | Sync API — POST / PUT / PATCH / DELETE | Writes and actions (DB writes, S3 writes, publishing messages). Flow: authorize → validate → business logic → transform → respond |
| Querier | Sync API — GET | Reads (DB queries, S3 reads). Same flow, with pagination and response size in mind |
| Subscriber | SQS (async events, incl. from S3) | Consumes async messages; idempotent and order-independent. Throws on failure so the message retries and ultimately lands in the DLQ. Often tuned with a higher timeout/memory |
| Scheduler | EventBridge cron | Runs scheduled jobs. Throws only when the run should retry |
| Publisher | Service's DDB stream | Publishes the corresponding SNS events when data changes |
| Streams | Service's DDB stream | Transforms stream records onto a Kinesis Firehose stream for the Redshift analytics pipeline |
| OLTP-Streams | Invoked by Streams (not the DDB stream directly) | Writes the forwarded records into the OLTP (Aurora) database |
Databases and buckets
A service can have any number of databases (or none), in one of two flavours:
- NoSQL — DynamoDB. A service may have multiple tables, but prefer keeping data in one table where possible.
- SQL — Postgres on serverless Aurora.
Databases must have Point-In-Time Recovery enabled and be backed up cross-account. Services can also have S3 buckets for storing objects (images, video, and so on); these are likewise backed up cross-account.
Queues and DLQs
If a service does async communication, it goes through a queue:
- One queue per service.
- A standard queue by default — FIFO where that's more appropriate.
- A batch size of 1, unless a larger batch is better for performance.
- Every queue has a DLQ, which retains messages for 14 days.
Topics
A service can have multiple topics, or none. Topics follow a one-topic-per-event rule — e.g. an andi-updated topic for the ANDI_UPDATED event.
Monitoring and alerting
Each service carries enough monitoring and alerting to be observable — alarms and alerts across its resources (the local API Gateway, Lambdas, queue/DLQ, and so on). Log groups and every other resource are defined as code so a service can be recreated from scratch with no manual resource creation.
Flavours of microservice
Every service is one — or a blend — of the archetypes below. The archetype drives which components a service has and how it relates to data and users. When designing a new service, work out its flavour by asking:
- Is it the source of truth for core domain data, or does it consume data owned by other services?
- Does it serve end users directly, or support other services behind the scenes?
- What does it depend on, and how does data flow in and out?
- How does it integrate with third-party systems?
- Is it single-purpose, or does it group related functionality and entities?
- Does it coordinate workflows across several services?
- What level does it operate at — domain-specific, platform-wide, or utility?
| Flavour | What it is | Examples |
|---|---|---|
| Domain | Source of truth for core entities. CRUD over API, owns a DynamoDB table, publishes events on change | expenses, shares |
| Feature | User-facing; aggregates and transforms data owned by domain services. May keep derived copies, but isn't the source of truth | revenue-forecast, reports |
| Utility | Generic, reusable capability (e.g. emails, PDF generation); idempotent, holds no core domain data | emails, pdf-generator, scheduler |
| Gateway | Integrates third-party systems via in/outbound webhooks; stores credentials; often a local API Gateway with public endpoints | finance-gateway, ai-gateway, employee-gateway |
| Micro-monolith | Several flavours fused around one strongly-cohesive entity (domain + feature together) | engagements, skills, invoices |
| Orchestrator | Coordinates workflows across services (e.g. Step Functions, scheduled fan-out); stores workflow metadata, not domain data | No current example. The marketing-qualified-leads service used to implement it (Step Functions state machine); see its code at the last commit before removal |
| Platform | Cross-cutting capability every service relies on; operates at the infrastructure level | auth, janitor |
Principles
The following principles are inter-linked and complement one another.
Separation of responsibility — principle of least knowledge
Responsibilities are separated into independent functionalities, each knowing only what it needs to. Read is separate from write; sync is separate from async; use only the information you need. CQRS is a good fit for this.
Observability, resilience, scalability (ORS)
Services are built to be observable (monitoring, alerting, the right level of logging), resilient to faults elsewhere in the system (and when they can't be, failing gracefully and meaningfully), and scalable to meet future demand.
Domain encapsulation
Domains are independent entities representing an atomic unit of business operations, and are the source of truth for their own data. No domain directly accesses or modifies another domain's data — dependent domains get it through the appropriate interface (messages or APIs).
Secure — principle of least privilege, zero trust
Services are secure by design and assume the principle of least privilege, holding access only to the resources they need.
One topic per event
Emit one SNS topic per event. This reduces Lambda invocations (and cost), allows finer granularity that helps observability and resilience, and keeps concerns separated per topic.
Business-centric modelling
Model services around the business, not around the technology.
