# Avatar Offloading to S3

**URL:** <https://meta.discourse.org/t/avatar-offloading-to-s3/46406>\
**Category:** Feature\
**Created:** [24. Juni 2016 um 15:44 UTC](https://meta.discourse.org/t/avatar-offloading-to-s3/46406 "2016-06-24T15:44:06Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [28. Juni 2016 um 00:00 UTC](https://meta.discourse.org/t/avatar-offloading-to-s3/46406/4 "2016-06-28T00:00:52Z")

</div>

We have been through this, and its complicated, complicated enough that a CDN is a fine solution and in practice scales us just fine.

Say I have an avatar:

`sam.png`

Now the client happens to need a copy of `sam.png` at 120x120px. How does it figure out how to get that?

Option 1:

Whenever server ships down avatar info to the client it ships an array of all the possible sizes of avatar the client may need eg:

```plaintext
{'sam.png' => [
   [10, 'http://somewhere/png1.png'],
   [20, 'http://somewhere/png2.png'],
   [40, 'http://somewhere/png3.png'],
   [50, 'http://somewhere/png4.png'],
   [60, 'http://somewhere/png5.png'],
   [70, 'http://somewhere/png6.png'],
   [80, 'http://somewhere/png7.png'],
   [90, 'http://somewhere/png8.png']
 ]
}

```

There are tons of locations cause with have retina vs. non retina and thus numerous device pixel ratios and multiple sizes of avatars the client may need.

Options 2:

We send a template

```plaintext
{ 'sam.png' => 'https://cdn.discourse.org/avatars/sam.{size}.png'}

```

We went with option 2, because option 1 is where madness lies. Option 2 scales super fine as our NGINX config will properly cache every avatar, and CDNS cache every avatar. So first hit warms up the CDN cache and second hit is served directly from CDN without going to the app.

---

_[View the full topic](https://meta.discourse.org/t/avatar-offloading-to-s3/46406)._
