---
title: "Rails 6.1 tracks Active Storage variant in the database"
description: "Rails 6.1 tracks Active Storage variant in the database"
canonical_url: "https://www.bigbinary.com/blog/rails-6-1-tracks-active-storage-variant-in-the-database"
markdown_url: "https://www.bigbinary.com/blog/rails-6-1-tracks-active-storage-variant-in-the-database.md"
---

# Rails 6.1 tracks Active Storage variant in the database

Rails 6.1 tracks Active Storage variant in the database

- Author: Abhay Nikam
- Published: June 30, 2020
- Categories: Rails 6.1, Rails

Active Storage variants are the transformation of the original image. These
variants can be used as thumbnails, avatars, etc.

Active Storage generates variants **on demand** by downloading the original
image. The image is transformed into a variant and is stored to the third party
services like S3.

When a request to fetch a variant for an Active Storage object is made, Rails
checks if the variant is already been processed and is already available on S3
or not. But to do so Rails has to make a call to find out if the variant is
available on S3. This extra call adds to the latency.

Active Storage has to wait until the image variant check call is completed
because S3 might not return the image when a GET request is made due to eventual
[consistency](https://docs.aws.amazon.com/AmazonS3/latest/dev/Introduction.html#ConsistencyModel).
This way Rails avoid downloading a broken image from S3 and uploading broken
image variant to S3 in case the variant is not present.

In Rails 6.1, Active Storage tracks the presence of the variant in the database.
This change avoids unnecessary variant presence remote request made to the S3
and directly fetches or generates a image variant.

In Rails 6.1, the configuration to allow variant tracking in the database is by
default set to true.

```ruby
config.active_storage.track_variants: true
```

Check out the [pull request](https://github.com/rails/rails/pull/37901) for more
details on this.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-6-1-tracks-active-storage-variant-in-the-database)
