Go to file
Alex Vandiver 04cf68b45e uploads: Serve S3 uploads directly from nginx.
When file uploads are stored in S3, this means that Zulip serves as a
302 to S3.  Because browsers do not cache redirects, this means that
no image contents can be cached -- and upon every page load or reload,
every recently-posted image must be re-fetched.  This incurs extra
load on the Zulip server, as well as potentially excessive bandwidth
usage from S3, and on the client's connection.

Switch to fetching the content from S3 in nginx, and serving the
content from nginx.  These have `Cache-control: private, immutable`
headers set on the response, allowing browsers to cache them locally.

Because nginx fetching from S3 can be slow, and requests for uploads
will generally be bunched around when a message containing them are
first posted, we instruct nginx to cache the contents locally.  This
is safe because uploaded file contents are immutable; access control
is still mediated by Django.  The nginx cache key is the URL without
query parameters, as those parameters include a time-limited signed
authentication parameter which lets nginx fetch the non-public file.

This adds a number of nginx-level configuration parameters to control
the caching which nginx performs, including the amount of in-memory
index for he cache, the maximum storage of the cache on disk, and how
long data is retained in the cache.  The currently-chosen figures are
reasonable for small to medium deployments.

The most notable effect of this change is in allowing browsers to
cache uploaded image content; however, while there will be many fewer
requests, it also has an improvement on request latency.  The
following tests were done with a non-AWS client in SFO, a server and
S3 storage in us-east-1, and with 100 requests after 10 requests of
warm-up (to fill the nginx cache).  The mean and standard deviation
are shown.

|                   | Redirect to S3      | Caching proxy, hot  | Caching proxy, cold |
| ----------------- | ------------------- | ------------------- | ------------------- |
| Time in Django    | 263.0 ms ±  28.3 ms | 258.0 ms ±  12.3 ms | 258.0 ms ±  12.3 ms |
| Small file (842b) | 586.1 ms ±  21.1 ms | 266.1 ms ±  67.4 ms | 288.6 ms ±  17.7 ms |
| Large file (660k) | 959.6 ms ± 137.9 ms | 609.5 ms ±  13.0 ms | 648.1 ms ±  43.2 ms |

The hot-cache performance is faster for both large and small files,
since it saves the client the time having to make a second request to
a separate host.  This performance improvement remains at least 100ms
even if the client is on the same coast as the server.

Cold nginx caches are only slightly slower than hot caches, because
VPC access to S3 endpoints is extremely fast (assuming it is in the
same region as the host), and nginx can pool connections to S3 and
reuse them.

However, all of the 648ms taken to serve a cold-cache large file is
occupied in nginx, as opposed to the only 263ms which was spent in
nginx when using redirects to S3.  This means that to overall spend
less time responding to uploaded-file requests in nginx, clients will
need to find files in their local cache, and skip making an
uploaded-file request, at least 60% of the time.  Modeling shows a
reduction in the number of client requests by about 70% - 80%.

The `Content-Disposition` header logic can now also be entirely shared
with the local-file codepath, as can the `url_only` path used by
mobile clients.  While we could provide the direct-to-S3 temporary
signed URL to mobile clients, we choose to provide the
served-from-Zulip signed URL, to better control caching headers on it,
and greater consistency.  In doing so, we adjust the salt used for the
URL; since these URLs are only valid for 60s, the effect of this salt
change is minimal.
2023-01-09 18:23:58 -05:00
.github contributing docs: Update "Version Control" > "Commit discipline" links. 2022-12-09 13:28:49 -08:00
.tx provision: Replace transifex-client with new transifex-cli. 2022-12-13 12:34:08 -08:00
.vscode vscode: Recommend remote development extension. 2021-11-03 16:03:46 -07:00
analytics ruff: Fix Q002 Single quote docstring found. 2023-01-04 16:25:07 -08:00
confirmation ruff: Fix N818 exception name should be named with an Error suffix. 2022-11-17 16:52:00 -08:00
corporate Fix typos caught by typos. 2023-01-03 11:09:50 -08:00
docs uploads: Serve S3 uploads directly from nginx. 2023-01-09 18:23:58 -05:00
frontend_tests util: Add function `get_string_diff`. 2023-01-06 16:53:57 -08:00
locale i18n: Update translation data from Transifex. 2022-12-02 12:14:38 -08:00
pgroonga typing: Use BaseDatabaseSchemaEditor in place of DatabaseSchemaEditor. 2022-05-30 14:18:53 -07:00
puppet uploads: Serve S3 uploads directly from nginx. 2023-01-09 18:23:58 -05:00
requirements uploads: Set X-Accel-Redirect manually, without using django-sendfile2. 2023-01-09 18:23:58 -05:00
scripts create-database: Hide harmless "non-existant database" warnings. 2023-01-05 11:39:23 -08:00
static typeahead: Make the typeahead completions undo friendly. 2023-01-06 16:53:57 -08:00
stubs/taint actions: Split out zerver.actions.message_send. 2022-04-14 17:14:34 -07:00
templates api-docs: Add `missing.md` file specifically for API documentation. 2023-01-09 11:17:00 -08:00
tools uploads: Split out S3 and local file backends into separate files. 2023-01-09 18:23:58 -05:00
var/puppeteer puppeteer_tests: Port to TypeScript. 2021-02-22 16:03:10 -08:00
zerver uploads: Serve S3 uploads directly from nginx. 2023-01-09 18:23:58 -05:00
zilencer ruff: Fix DTZ005 `datetime.datetime.now()` without `tz` argument. 2023-01-04 16:25:07 -08:00
zproject uploads: Serve S3 uploads directly from nginx. 2023-01-09 18:23:58 -05:00
.browserslistrc zjsunit: Set browserslist target to current Node for Node tests. 2022-05-04 09:56:07 -07:00
.codecov.yml
.codespellignore contributor docs: Add a page on design discussions. 2022-09-30 12:15:04 -07:00
.editorconfig editorconfig: Restore indent_size = 2 for Markdown. 2021-08-20 23:14:37 -07:00
.eslintignore requirements: Remove Thumbor. 2021-05-06 20:07:32 -07:00
.eslintrc.json eslint: Add root: true. 2023-01-03 13:59:25 -08:00
.gitattributes .gitattributes: Mark *.bmp, *.bson, *.mp3, *.pdf as binary. 2022-02-07 18:51:06 -08:00
.gitignore lint: Replace pycodestyle and pyflakes with ruff. 2022-11-03 12:10:15 -07:00
.gitlint lint: Re-enable imperative-mood checking. 2021-02-23 14:54:07 -08:00
.mailmap mailmap: Add entry for rht. 2022-11-17 00:05:17 -08:00
.npmignore
.prettierignore prettier: Exclude backend-processed Markdown files. 2021-08-20 23:14:37 -07:00
.pyre_configuration
.sonarcloud.properties
.yarnrc
CODE_OF_CONDUCT.md contributor docs: Add guidelines on moderating the Zulip community. 2022-12-02 16:57:41 -08:00
CONTRIBUTING.md contributor docs: Add guidance on claiming a second issue. 2022-12-14 21:11:47 -08:00
Dockerfile-postgresql docker: Document the PostgreSQL Dockerfile build steps. 2022-04-26 18:00:00 -07:00
LICENSE
NOTICE docs: Bump copyright year. 2021-02-05 09:28:15 -08:00
README.md README: Add Ruff badge. 2023-01-04 16:22:12 -08:00
SECURITY.md SECURITY.md: Reorder and make clearer how to subscribe to announcements. 2022-01-07 15:56:26 -08:00
Vagrantfile vagrant: Add Fedora 36 support. 2022-09-08 16:12:59 -07:00
babel.config.js dependencies: Upgrade JavaScript dependencies. 2023-01-04 12:30:04 -08:00
manage.py ruff: Fix PIE807 Prefer `list()` over useless lambda. 2023-01-04 16:25:07 -08:00
package.json dependencies: Upgrade JavaScript dependencies. 2023-01-04 12:30:04 -08:00
postcss.config.js css: Replace "night-mode-block" with "dark-theme-block". 2021-11-26 22:03:29 -08:00
prettier.config.js prettier: Disable embedded language formatting for Markdown. 2021-08-20 23:14:37 -07:00
pyproject.toml uploads: Set X-Accel-Redirect manually, without using django-sendfile2. 2023-01-09 18:23:58 -05:00
stylelint.config.js yarn: Add package which allows creating css mixins. 2021-12-09 18:15:18 -08:00
tsconfig.json tsconfig: Enable noImplicitOverride. 2021-09-13 10:10:34 -07:00
version.py uploads: Set X-Accel-Redirect manually, without using django-sendfile2. 2023-01-09 18:23:58 -05:00
webpack.config.ts webpack: Add a hook to print a compilation successful message. 2022-09-07 17:30:06 -07:00
yarn.lock dependencies: Upgrade JavaScript dependencies. 2023-01-04 12:30:04 -08:00

README.md

Zulip overview

Zulip is an open-source team collaboration tool with unique topic-based threading that combines the best of email and chat to make remote work productive and delightful. Fortune 500 companies, leading open source projects, and thousands of other organizations use Zulip every day. Zulip is the only modern team chat app that is designed for both live and asynchronous conversations.

Zulip is built by a distributed community of developers from all around the world, with 74+ people who have each contributed 100+ commits. With over 1000 contributors merging over 500 commits a month, Zulip is the largest and fastest growing open source team chat project.

Come find us on the development community chat!

GitHub Actions build status coverage status Mypy coverage Ruff code style: black code style: prettier GitHub release docs Zulip chat Twitter GitHub Sponsors

Getting started

You may also be interested in reading our blog, and following us on Twitter and LinkedIn.

Zulip is distributed under the Apache 2.0 license.