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

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

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

#### Key Facts

- Tip **#66**
- For **Ops and infrastructure**
- Category **Containers, Kubernetes and serverless**
- Format **short video**
![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/)
