# Managed Valkey

Run Valkey, the open-source Redis-compatible in-memory data store, for caching, sessions and queues, without a server to look after. We take care of provisioning, failover and patch updates.

## Create a Valkey database

1. Go to **Databases** and click **Create database**.
2. Select **Valkey**.
3. Enter a **Name**. It must be unique in your organization.
4. Select the **Data center** your servers run in. See [Regions](https://betterstack.com/docs/cloud/servers/regions/#choose-a-region).
5. Select a **Plan**.
6. Under **Nodes**, select **Primary + 1 replica**, so a replica takes over if the primary fails.
7. Turn on **Allow public access** if clients outside your private networks connect to the database.
8. Click **Create database**.

The database is ready when its status reads **Running**.

![Create database form with Valkey selected](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/044bb98a-5e13-409a-8ed2-718303fea300/md2x =2180x2156)

## Plans

| Plan | vCPU and RAM | Memory for data | Connections |
|------|--------------|-----------------|-------------|
| VK1 | 4 vCPU, 4 GB | 3 GB | 20,000 |
| VK2 | 8 vCPU, 8 GB | 6 GB | 40,000 |
| VK3 | 8 vCPU, 32 GB | 24 GB | 40,000 |
| VK4 | 16 vCPU, 64 GB | 48 GB | 80,000 |
| VK5 | 32 vCPU, 120 GB | 90 GB | 160,000 |
| VK6 | 48 vCPU, 160 GB | 120 GB | 240,000 |
| VK7 | 64 vCPU, 192 GB | 144 GB | 320,000 |
| VK8 | 128 vCPU, 480 GB | 360 GB | 640,000 |

Every node gets the full plan and bills at the plan's price, so a primary with one replica costs twice the plan. Memory for data is Valkey's memory limit. We keep the rest of the RAM for background saves and replication, so a full instance never runs out of memory. Traffic over private networks, replication included, is free. See [Pricing philosophy](https://betterstack.com/docs/cloud/pricing/#network-and-ip-address-prices) for internet egress.

## Connect to your database

Open the database and find the hostname, the `default` user and its **AUTH token** under **Connection**. Set the hostname as `VALKEY_HOST` and connect:

[code-tabs]
```bash
[label Private network]
valkey-cli -h "$VALKEY_HOST" -p 6379 --askpass
```
```bash
[label Public access]
valkey-cli --tls --cacert betterstack-db-ca.pem -h "$VALKEY_PUBLIC_HOST" -p 6380 --askpass
```
[/code-tabs]

A new database is reachable only from the [private networks](https://betterstack.com/docs/cloud/networks/private-networks/) attached to it, on port **6379** without TLS. The hostname always points at the current primary, so clients follow a failover by reconnecting.

**Allow public access** opens port **6380** on a separate public hostname, with TLS only. The plain port is never public. Certificates are issued by the Better Stack Managed CA, which isn't in system trust stores, so pass the CA certificate to your client. `betterstack valkey credentials <name> --availability-zone us-west-2a` returns the public hostname in `tls_uri` and the CA certificate in `ca_certificate`. Save the certificate as `betterstack-db-ca.pem` and set the public hostname as `VALKEY_PUBLIC_HOST`. Restrict who can connect with a [firewall](https://betterstack.com/docs/cloud/networks/firewalls/). A firewall filters only the public address, not traffic from private networks.

[info]
#### Connection hangs from outside Cloud?
The hostname resolves to a private address, so it works only from your private networks. From the internet, turn on public access and connect to the public hostname.
[/info]

## Rotate credentials

To replace the AUTH token:

1. Click **Rotate credentials** on the database page.
2. Click **Rotate credentials** to confirm.

The previous token keeps working for 24 hours, and open connections stay up, so roll your clients within that window. Only two tokens are valid at once, so rotating again within the 24 hours retires the oldest token right away.

## Authentication and commands

AUTH is always on, with a single `default` user. Every data command works as usual. Commands that would break the managed service are blocked: `SHUTDOWN`, `REPLICAOF` and `SLAVEOF`, `FAILOVER`, `CONFIG`, `DEBUG`, `MODULE`, `ACL`, `SAVE`, `BGSAVE`, `BGREWRITEAOF` and `CLUSTER`.

The database runs as standalone Valkey, not Valkey Cluster, so configure client libraries for standalone mode. A client that probes for a cluster gets `ERR This instance has cluster support disabled`.

Valkey saves your data to disk periodically, so a restarted node comes back with recent data. When data reaches the memory limit, the `noeviction` policy applies, so Valkey keeps every key and returns an error for writes that need more memory.

## Replicas and failover

Replicas run in the same data center and copy the primary asynchronously. They serve read-only traffic.

With at least one replica, failover is automatic. When the primary is unreachable for about 90 seconds, the most caught-up replica becomes the primary and the hostname moves to it. Writes fail for about 2 minutes end to end.

Because replication is asynchronous, writes that hadn't reached that replica yet are lost. A database without replicas has no failover and is down until its node recovers.

To switch on purpose, for a disaster recovery drill or a planned move:

1. Click **Fail over** on the database page.
2. Click **Fail over** to confirm.

No committed write is lost, and writes fail for about 20 seconds while clients reconnect.

[warning]
#### Seeing READONLY errors after a failover?
The old primary stays reachable and rejects writes with `READONLY You can't write against a read only replica`. Treat it as a signal to reconnect and re-resolve the hostname, and don't cache DNS beyond its 60-second TTL.
[/warning]

## Snapshots

Click **Take a snapshot** on the database page. The database keeps serving while the snapshot is taken, and a restore holds your data as of a few seconds before the capture. Snapshots outlive the database. To restore one, see [Database snapshots](https://betterstack.com/docs/cloud/databases/snapshots/#roll-a-database-back).

## Rescale and memory

To change the plan:

1. Click **Rescale** on the database page.
2. Select a **Plan** and click **Rescale database**.

With replicas, nodes resize one at a time and clients see a single reconnect.

A database without replicas is unavailable for a few minutes, longer for a big dataset, because Valkey reads it back from disk before it answers again. You can move to a smaller plan only if the memory in use fits within 90% of its memory for data, so delete or expire keys first.

## Updates

We apply Valkey patch releases automatically.

## Need help?

Please let us know at hello@betterstack.com.  
We're happy to help! 🙏
