Backend Development 16 min read

Designing a Three‑Level HTTP Cache in B/S Architecture and Optimizing Microservice Gateways

This article explores the shortcomings of current HTTP caching practices, proposes a three‑level cache design for B/S architectures, discusses gateway simplification with Apache APISIX, offers data‑size reduction tips, and presents a hand‑crafted Java HTTP cache framework with code examples.

Top Architect
Top Architect
Top Architect
Designing a Three‑Level HTTP Cache in B/S Architecture and Optimizing Microservice Gateways

The author, a senior architect, shares a candid view on why many developers overlook HTTP caching and how to redesign it for high‑concurrency web services.

1. Three‑level HTTP cache design – The article explains that most traffic is read‑heavy, why server‑side cache control (Cache‑Control, ETag, max‑age) is essential, and how proper cache negotiation can dramatically reduce backend load.

2. Short and concise – A humorous critique of over‑engineered microservice stacks, emphasizing that shortening the request path and reducing payload size are the first steps to performance gains.

3. Gateway optimization – Compares traditional Nginx + Spring Cloud Gateway setups with Apache APISIX, highlighting dynamic routes, upstream management, and service discovery. The author argues that a single traffic gateway (APISIX) can replace the multi‑layer approach, yielding 2‑8% latency improvements.

4. Data size reduction – Recommendations include avoiding select * , compressing JSON keys via @JsonProperty , using FastJSON2, enabling gzip in Spring Boot, and leveraging protocol‑level compression (e.g., HTTP/2). Small‑field tables and separating static data (e.g., product info) from frequently changing fields are also suggested.

5. Architecture precision – Warns against adding unnecessary middleware for the sake of “high‑tech” appearances; stresses that the simplest design that meets business needs usually yields the best performance.

6. Hand‑crafted HTTP cache framework – Provides source links and two code snippets demonstrating custom annotations @HttpCacheControl and @HttpETag that automatically set Cache‑Control and Etag headers.

@GetMapping("cache/{id}")
@HttpCacheControl(key = "#id", maxAge = 10)
public String getCache(@PathVariable String id) {
    return ResponseEntity.ok()
        .body(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
}
@PostMapping("cache/{id}")
@HttpETag(key = "#id")
public ResponseEntity
> modify(@PathVariable String id) {
    cacheService.modify(id);
    return ResponseEntity.ok()
        .body(new LinkedHashMap
() {{
            put("data", "modify: " + id);
        }});
}

The article concludes with an invitation for readers to discuss the ideas, provides additional reading links, and includes several promotional calls‑to‑action for community groups and interview material.

Javaperformance optimizationbackend architectureMicroservicesSpring Cloud GatewayHTTP Caching
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.