Senses and skin
Humans experience the world through senses: sight, hearing, touch, a clock-like sense of time. A microservice senses the world through inputs. Some inputs arrive when someone talks to it directly; others arrive as background noise it has chosen to listen to.
The five senses of a microservice
| Human sense | Service input | Example | AWS |
|---|---|---|---|
| Hearing someone speak to you | A direct request expecting an answer | "Place this order" | API Gateway → Lambda |
| Reading a letter | A message in its inbox, processed when ready | "Cook order #42" | SQS → Lambda |
| Overhearing an announcement | An event published by another service | "Payment completed" | EventBridge rule → Lambda/SQS |
| Sense of time | A schedule | "Every night at 2 a.m., send the daily report" | EventBridge Scheduler |
| Touch — something placed in your hands | A file arriving | "A menu photo was uploaded" | S3 event notification |
The UI of your application is the most important sense of the whole society — it's how humans outside the system (your users) reach it. In this handbook, the UI (web app, mobile app, chat, email) is the eyes and ears of the ecosystem, and API Gateway is the ear canal that carries what users say to the right human.
Synchronous vs asynchronous senses
- Synchronous (someone is waiting): API requests. The caller stands in front of you until you answer. Respond quickly — slow answers frustrate everyone.
- Asynchronous (nobody is waiting): letters, announcements, schedules, files. You can take your time, retry if you fail, and handle bursts calmly.
A good habit: acknowledge quickly, work later. When a customer places an order, say "Got it, order #42" immediately, then do the slow work asynchronously. Your senses stay free for the next customer.
The skin: deciding what gets in
Skin is a boundary. It lets good things in and keeps dirt out. For a service, the skin is its contract — what inputs it accepts — and validation that enforces it.
// skin/place-order.schema.ts — the shape of a valid "place order" request
import { z } from "zod";
export const PlaceOrder = z.object({
tableNumber: z.number().int().min(1).max(50),
items: z
.array(z.object({ menuItemId: z.string().min(1), quantity: z.number().int().min(1).max(20) }))
.min(1),
notes: z.string().max(200).optional(),
});
export type PlaceOrder = z.infer<typeof PlaceOrder>;
// senses/place-order.http.ts — the ear: thin handler, validates at the skin, passes to the brain
import type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from "aws-lambda";
import { PlaceOrder } from "../skin/place-order.schema";
import { placeOrder } from "../brain/place-order";
import { menu } from "../memory/menu"; // adapters that give the brain what it needs
import { orderMemory } from "../memory/order-memory";
import { voice } from "../voice/event-voice";
export const handler = async (event: APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> => {
const parsed = PlaceOrder.safeParse(JSON.parse(event.body ?? "{}"));
if (!parsed.success) {
return { statusCode: 400, body: JSON.stringify({ error: "Invalid order", details: parsed.error.issues }) };
}
const order = await placeOrder(parsed.data, { menu, memory: orderMemory, voice });
return { statusCode: 201, body: JSON.stringify(order) };
};
(This example uses the zod library for schemas; any validation approach works. API Gateway REST APIs can also validate request bodies before your code runs.)
Rules for healthy senses
- Keep handlers thin. A sense organ passes signals to the brain — it doesn't think. Handlers parse, validate and delegate.
- Validate everything at the skin. Never let unvalidated input reach the brain or memory.
- Expect noise. Events and messages can arrive twice or out of order. Design for it (see voice and hearing).
- Protect against overload. Throttle APIs; put a queue in front of slow work so bursts become a manageable stream.
- Document your senses. Other teams need to know which inputs you accept: an API specification for requests, event schemas for events.
The senses in AWS, summarised
| Input | Service | Notes |
|---|---|---|
| HTTP requests | API Gateway (HTTP or REST API), Lambda function URLs, ALB | Authentication, throttling, CORS at the edge |
| Messages | SQS | Buffering, retries, dead-letter queue |
| Events | EventBridge | Content-based filtering, many sources |
| Streams | Kinesis, DynamoDB Streams | Ordered, high-volume |
| Schedules | EventBridge Scheduler | One-time and recurring |
| Files | S3 events | Trigger on upload |
| Real-time two-way | API Gateway WebSocket, AppSync | Live updates |
Senses gather; skin filters; the brain decides. If your handler is making business decisions, your senses are doing the brain's job.