Architectural task: the notification service uses templates from the admin service. How to ensure reliability in case the admin service fails?
sobes.tech AI
Answer from AI
To ensure the reliability of the notification service when the admin service, which provides templates, goes down, several approaches can be used:
-
Template caching — the notification service should locally cache templates received from the admin service. If the admin service fails, the notification service will continue to use the last valid cache.
-
Asynchronous template updates — update templates in the background so as not to block notification sending.
-
Backup template storage — store templates in a database or a distributed storage accessible independently of the admin service.
-
Fallback templates — have basic default templates that are used if access to current templates is unavailable.
An example of caching in Go (simplified):
var templateCache map[string]string // key — template name
func getTemplate(name string) (string, error) {
tmpl, ok := templateCache[name]
if ok {
return tmpl, nil
}
// Attempt to fetch template from admin service
tmpl, err := fetchTemplateFromAdminService(name)
if err != nil {
// fallback: return an error or default template
return defaultTemplate(name), nil
}
templateCache[name] = tmpl
return tmpl, nil
}
Thus, the notification service becomes resilient to admin service unavailability.