---
title: "Tech Tip #66: Go stateless so you can scale down (video)"
description: "Your service can't scale down because it remembers too much."
url: https://greencode.ai/shorts/66-go-stateless-to-scale-down/
---

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

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

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

[Watch the video](https://media.greencode.ai/shorts/go-stateless-to-scale-down-a5511d0d7eff.mp4)

Video created by [explainapaper.com](https://explainapaper.com/?utm_source=greencode.ai&utm_medium=film&utm_campaign=made-by)

### 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](https://greencode-constitution.org/?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode) (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](https://keda.sh/?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode): 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](https://greencode.ai/feature/infrastructure-carbon-footprint-assessment/).

### Tags

#kubernetes#autoscaling#microservices

### Sources

- [Green Software Foundation, Green Software Patterns: Implement stateless design](https://github.com/Green-Software-Foundation/patterns/blob/main/docs/architecture/system-topology/implement-stateless-design.md?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode)
- [GreenCode Constitution skill, energy anti-patterns: H12 stateful service design: externalise state to enable horizontal scaling](https://greencode-constitution.org/skill.md?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode)

### 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.

[The tip in full](https://greencode.ai/tech-tips/66-go-stateless-to-scale-down/)

[« Tech Tip #65: Make the efficient mode the default](https://greencode.ai/shorts/65-eco-mode-by-default/)

[All GreenCode Tech Tips](https://greencode.ai/tech-tips/) · [All GreenCode videos](https://greencode.ai/videos/)

#### Key Facts

- Tip **#66**
- For **Ops and infrastructure**
- Length **1:09**
- Category **Containers, Kubernetes and serverless**
![GreenCode](https://greencode.ai/wp-content/uploads/2024/12/greencode-logo-website-small-colours-2.webp)

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

[Get in touch](https://greencode.ai/contact/)
