This article details Samsung's architectural shift from a stateful, asynchronous caching system to a stateless, real-time pricing engine using AWS Lambda Response Streaming and CloudFront. The key driver was eliminating price inconsistencies and high latency in their e-commerce platform during high-traffic events like Black Friday, which arose from a legacy data aggregation layer. The new solution leverages parallel fan-out and immediate response streaming to deliver accurate, up-to-date pricing.
Read original on AWS Architecture BlogSamsung faced significant issues with their legacy e-commerce pricing architecture, particularly on high-density Product Listing Pages (PLPs) and comparison tables. The system relied on a Data Aggregation (DA) service that precomputed prices hourly for an entire product catalog and stored them in a local cache. While this improved read speeds, it introduced two major problems:
To address these issues, Samsung adopted a stateless streaming architecture centered around a "Bulk Arbitration Engine." This new approach eliminates the intermediate stateful cache by directly querying the authoritative Pricing Engine at request time. The core components include:
Key Architectural Shift
The fundamental design change was moving from an asynchronous, precomputed caching model to a synchronous, real-time, stateless orchestration model. This directly tackles data staleness by removing the "desynchronization layer" and leveraging streaming for improved perceived latency.
export const handler = awslambda.streamifyResponse(
async (event, responseStream, _context) => {
try {
// Set response metadata with status code and headers
const httpResponseMetadata = {
statusCode: 200,
headers: {
"Content-Type": "application/x-ndjson",
"Content-Encoding": "gzip",
"Cache-Control": "public, max-age=300", // 5 min cache
"X-Custom-Header": "lambda-streaming",
},
};
responseStream = awslambda.HttpResponseStream.from(
responseStream,
httpResponseMetadata
);
const ndjsonTransform = new NDJSONTransform();
const gzip = zlib.createGzip({ level: zlib.constants.Z_BEST_SPEED });
await processRequestUsingQueryString(event, ndjsonTransform, _context);
await pipeline(ndjsonTransform, gzip, responseStream);
} catch (error) {
console.error("Lambda streaming error:", error);
responseStream.destroy();
} finally {
await flushMetrics().catch(console.error);
}
}
);The Lambda handler uses `awslambda.streamifyResponse()` to enable streaming. It pipelines a custom `NDJSONTransform` and a `zlib.createGzip` stream (with `Z_BEST_SPEED` for faster compression) to the `responseStream`. The `processRequestUsingQueryString` function parses SKUs from the query string, fans out requests to the pricing engine using `Promise.all` for parallel execution, and writes each result as a separate NDJSON line to the transform stream. This allows clients to receive and process pricing data incrementally.