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.
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.
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:
- Fabulous Claim-Check Design Pattern explained in just one minute
- Circuit Breaker Pattern in 30 seconds
- 4+1 helpful and important Cloud Design Patterns explained in short time