# Sticky session

A sticky session binds a series of requests to one exit IP address for a defined duration, instead of rotating on every connection. The client attaches a session identifier to its proxy username; every connection carrying the same identifier is routed through the same exit until the session lifetime ends or the exit goes offline. Sticky sessions make logins, shopping carts and multi-page flows work through a rotating pool.


## How it is expressed

Two parameters: a session id you choose and a lifetime. On ProxShift they are `-sid-<id>` and `-ttl-<duration>` in the username; other providers use similar keys. Change the id and you get a new exit immediately; reuse it and you get the same exit for as long as the lifetime allows.

```text
http://USER-cc-us-sid-cartA-ttl-30m:PASS@res.proxshift.com:9000
http://USER-cc-us-sid-cartB-ttl-30m:PASS@res.proxshift.com:9000
```


## How long is long enough

- A search followed by three result pages: a few minutes.
- A checkout with address and payment steps: 10 to 30 minutes.
- Account activity that must look like one device for the day: hours, up to the provider's maximum.
- Weeks or months on one address: not a sticky session at all; that is an [ISP proxy](https://proxshift.com/glossary/isp-proxy).


## What happens when the exit disappears

Household devices go offline. A well-designed gateway detects it, binds the session to another device in the same location and the session continues with at most one failed request. Your code should retry once on connection errors for exactly that reason.


## How it works at ProxShift

ProxShift sticky sessions hold an exit from 1 minute to 24 hours (-ttl-, default 10 minutes) on both the residential and the mobile gateway; -sid- accepts up to 32 characters, a-z and 0-9. Lost exits are replaced in the same location.

## Questions

**Does a sticky session guarantee the same IP for the whole TTL?**

It guarantees the gateway will try. If the household behind the exit disconnects, the session moves to another exit in the same location; nothing can keep a device online that its owner switched off.

**Can I run many sticky sessions at once?**

Yes, as many as you like, each with its own id. This is how account-per-session or basket-per-session workloads are built on a pool.

Source: https://proxshift.com/glossary/sticky-session
