Menu
AWS Architecture Blog·June 15, 2026

Real-time Pricing with Stateless Streaming and Edge Caching

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 Blog

The Challenge: Latency and Data Staleness in E-commerce Pricing

Samsung 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:

  • Permutation Explosion: The DA service had to precompute every possible combination of product variants, offers, and add-ons, leading to an exponential growth in cache size and wasted compute resources for combinations never requested.
  • Synchronization Lag: The hourly cron job caused up to a 1-hour desynchronization gap between the authoritative pricing engine and customer-facing pages. This resulted in incorrect prices being displayed during flash sales and a poor customer experience, leading to "cart shock" when checkout prices differed from advertised prices.

Solution: Stateless Streaming Architecture with AWS Lambda and CloudFront

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:

  • AWS Lambda Response Streaming: This feature allows a Lambda function to fan out multiple pricing requests to the backend Pricing Engine in parallel and stream results back to the client as they arrive, without buffering the entire response. This significantly reduces time-to-first-byte (TTFB).
  • Amazon CloudFront Edge Caching: CloudFront is used as an edge cache to serve responses for approximately 95% of traffic, reducing the load on the Lambda function and the Pricing Engine. For cache misses, requests are routed directly to the Lambda function for real-time processing.
  • NDJSON (Newline-Delimited JSON) Transformation: Within the Lambda, a custom transformation converts pricing objects into NDJSON. This allows the client-side browser to parse and render individual prices incrementally as they stream in, rather than waiting for the complete aggregated response.
💡

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.

Lambda Implementation Details

javascript
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.

AWS LambdaCloudFrontResponse StreamingE-commerceReal-time DataStateless ArchitectureCaching StrategiesAPI Design

Comments

Loading comments...