The inspiration for this blog post is API response in a video by Chaos Monkey for Spring Boot
A typical pattern for handling network assaults is Circuit Breaker.
A circuit breaker would replace a network delay or failure code with a fallback code, making the code resilient.
Ideally, the user is indicated when fallback data is used.
This can be as simple as adding a
responseMetadata field within HTTP Response.
type: "STALE", // STALE, LATEST, FALLBACK
type could be
STALEfor old data
LATESTto indicate the data is current
- date of when something is updated
The frontend or client could read the
responseMetadata and show a message to the user indicating that old data.
The client could also take further action on
responseMetadata, like polling, after a little while until the response is
responseMetadata can be part of a parent class for all response classes. An ArchUnit test canenforce this behaviour.