Tech Tip #66: Go stateless so you can scale down

Your service can't scale down because it remembers too much.

Video created by explainapaper.com

The problem

Services that keep sessions and data in memory or on local disk need big instances and can't be removed when traffic falls, so they run at peak size all day.

The fix you can use today

  • Move session and state into a database or shared cache.
  • Make instances interchangeable so any one can be removed.
  • Then turn on autoscaling, including scale-in.

The Green Software Foundation suggests keeping services stateless, so they can scale down. GreenCode's energy rules for AI coding agents cover this too.

Tools that help

  • GreenCode Constitution skill (GreenCode researchers): open-source energy principles and a catalogue of 37 energy anti-patterns that an AI coding agent can follow to find and fix waste like this
  • KEDA: event-driven autoscaling for Kubernetes, including scaling a workload to zero when there is nothing to do

How GreenCode helps

GreenCode helps tackle this by mapping a running estate, rebuilding it as infrastructure as code and showing which services use the energy, including services running hot and services barely running at all. More on this.

Tags

#kubernetes#autoscaling#microservices

Sources

All GreenCode Tech Tips

  • Tip #66
  • For Ops and infrastructure
  • Category Containers, Kubernetes and serverless
  • Format short video
GreenCode

Want this checked on your own system? Talk to the GreenCode team.

Get in touch