DEV Community

Mirco
Mirco

Posted on • Originally published at Medium on

Valet Key Design Pattern in 30 Seconds

Do not waste your applications resources on big uploads.


Photo by Old Money on Unsplash

Routing large up- and downloads through your application absorbs valuable resources like bandwidth and CPU time. After the service authenticated the upload request, it uploads data to a storage system like Amazon S3 or Google Cloud Storage. Authentication is fast. The service wastes most of its time while it waits for the file to be saved by the storage system.


The service wastes most of its time while it waits for the file to be saved by the storage system.Uploading via the service locks resources.

Why waste so much valuable time? The Valet Key Pattern creates a remedy for this problem.

Clients do not call your service anymore to upload things. They only call your service to get a specialized key with limited validity. Then, they use this key to upload their data directly to the storage system. The storage system must be able to verify that the key is valid. In this way, your application will not have to wait for the upload.


Use the Valet Key Pattern to reduce load on your system.

On the downside, you lose some control over your storage system. You have to ensure that the key has the lowest possible scope. Limit the maximum upload size, the reusability of the key and its validity. If possible, make the client notify you after the upload is finished, so that you can invalidate the key right away.

Do not forget to validate and sanitize all uploaded data before using it. You can achieve this with an own service which regularly scans all new uploads.

Use this pattern only if clients must upload extensive files often. It will save you resources. And this will save you money.

Want to learn more about Cloud Design Patterns? Check out these articles:


If this article was helpful for your, please consider to buy me a coffee :-)
ko-fi

Top comments (0)