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

Transcript

Your service cannot scale down, because it remembers too much. Some services keep sessions and data in memory, or on their own disk. So they need big machines. And no copy can be removed when traffic falls. They run at peak size all day, even at night. The Green Software Foundation suggests keeping services stateless, so they can scale down. GreenCode's energy rules for AI coding agents cover this too. Here is the fix you can use today. Move sessions and state into a database or a shared cache. GreenCode's Constitution skill can help AI coding agents spot stateful services. Make every copy the same, so any one can be removed. Then turn on autoscaling, including scaling in, using tools like KEDA. Now your service can shrink when demand does. GreenCode helps tackle this by mapping your running systems and rebuilding them as code. It shows which services use the energy, including ones barely running at all. That was GreenCode Tech Tip number sixty-six. Follow for the next tip, and find more on greencode.ai/tech-tips.

All GreenCode Tech Tips · All GreenCode videos

  • Tip #66
  • For Ops and infrastructure
  • Length 1:09
  • Category Containers, Kubernetes and serverless
GreenCode

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

Get in touch