This blog is part of our Rails 6.1 series.
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. 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.
Check out the pull request for more details on this.