Scalable APIs for Distributed Generation with Node.js/TypeScript on AWS
Monitoring Distributed Generation (DG) solar power plants requires fast and reliable data ingestion. Photovoltaic inverters send generation logs every 5 or 15 minutes, generating constant telemetry traffic that needs to be processed, stored, and utilized for billing energy balance.
In this article, I present the design of a resilient microservices architecture built with Node.js, TypeScript, and hosted on AWS, combining serverless processing with event-driven message buses.
Architecture Design
To ensure scalability with low operational costs, we implemented the following API topology:
- API Gateway: Public entry point for receiving JSON payloads sent by inverters.
- AWS SQS (Simple Queue Service): Immediate decoupling of requests to avoid bottlenecks during telemetry spikes.
- AWS Lambda (Serverless Node.js): Functions focused on parsing data payloads, validating electrical parameters, and storing consolidated data.
- AWS Aurora PostgreSQL: Structured final storage for quick reports and operational auditing.
Code Sample (TypeScript)
The function that processes telemetry is the Lambda subscribed to the queue. API Gateway authenticates and enqueues. If energyKwh is not a number, the handler returns that messageId in batchItemFailures. SQS redelivers it and, after the redrive policy's maxReceiveCount, the message lands in the DLQ instead of becoming junk in Aurora.
import type { SQSHandler } from 'aws-lambda';
type Telemetry = {
inverterId: string;
energyKwh: number;
timestamp: string;
};
export function parseTelemetry(body: string): Telemetry {
const data = JSON.parse(body) as Telemetry;
if (typeof data.inverterId !== 'string' || data.inverterId.length === 0) {
throw new Error('missing inverterId');
}
if (typeof data.energyKwh !== 'number' || Number.isNaN(data.energyKwh)) {
throw new Error('invalid energyKwh');
}
return data;
}
export const handler: SQSHandler = async (event) => {
const failures: { itemIdentifier: string }[] = [];
for (const record of event.Records) {
try {
const telemetry = parseTelemetry(record.body);
console.log(`[INFO] Inverter ${telemetry.inverterId}: ${telemetry.energyKwh} kWh`);
} catch (error) {
console.error('[ERROR]', error);
failures.push({ itemIdentifier: record.messageId });
}
}
return { batchItemFailures: failures };
};
If the edge is a container on ECS instead of API Gateway, Express returns 202 only after it publishes to the same queue. Without SendMessage, the 202 is a lie.
import { Request, Response } from 'express';
import { SQSClient, SendMessageCommand } from '@aws-sdk/client-sqs';
const sqs = new SQSClient({});
export class InverterController {
async processTelemetry(req: Request, res: Response) {
const { inverterId, energyKwh, timestamp } = req.body;
await sqs.send(new SendMessageCommand({
QueueUrl: process.env.QUEUE_URL,
MessageBody: JSON.stringify({ inverterId, energyKwh, timestamp }),
}));
return res.status(202).json({ status: 'queued' });
}
}
From the plant to the queue
The command below is the operator's test, not the inverter's path. Without the queue, an inverter spike at noon stalls the API.
aws sqs send-message \
--queue-url "$QUEUE_URL" \
--message-body '{"inverterId":"INV-14","energyKwh":4.2,"timestamp":"2026-05-20T15:00:00Z"}'
Benefits of TypeScript in Solar Engineering
Static typing prevents inconsistencies in energy allocation calculations for solar energy cooperatives: a field that arrives as text ("4.2") cannot enter a sum without an explicit conversion, a classic dynamic JavaScript bug. It does not fix floating-point rounding; for currency values, compute in integer cents or use a decimal library.
Related Articles
Multi-cloud for Banks: Separating the Core, Data, and the Audit Trail
Multi-cloud architecture for banks: a locked region, a core isolated from the lab, and an audit trail nobody can delete. SCP, CloudTrail, and Object Lock commands.
SAP Business One with SAP HANA on AWS: Architecture and Day-to-Day Operations
How to run SAP Business One on SAP HANA on AWS: instance, data and log volumes, port 30015, and backup. Power BI reads the replica, not production HANA.