Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

Handling Large Blobs (HelloInterview) のメモ

0
Last updated at Posted at 2026-04-05

この記事で学んだことをメモる。

Patterns

S3 における Signature Verification (署名検証)

S3 presigned URL / CDN signed URL のそれぞれを以下にまとめた。

HTTP range header

todo

DD :one: "What if the upload fails at 99%?"

-> Use S3 multipart upload.
(100MB 以上で推奨。各partialは 5MB 程度。 S3 SDKでは内部でやってくれてる。)

Design Dropbox - DD1: How can you support large files? が詳しい。

🟢 how will we handle resumable uploads?
Chunk ごとのアップロード状態を保持しておく。
After the disconnection, the client calls ListParts API in S3, and confirm which parts have already been uploaded. Then it resumes uploading the missing partials.

🟢 how should we ensure this chunks field is kept in sync with the actual chunks that have been uploaded?

checksumを使う。Chunk ごとに checksum を使って破損検知を行う。

🟢 アップロードの完了検知

クライアント側が全てのアップロードが完了したら、CompleteMultipartUpload API をコールする。
S3側で、本当に全てのアップロードが終わっているかを確認する。(= Trust but Verify)

アプリ側のメタデータに upload_status (pending, failed, succeeded) を持っておき、S3 event notificaiton を利用して、ファイル全体のアップロード完了後に書き換える。S3 --CDC--> Worker ---> PostMetadata

🟢 アップロードが途中で失敗終了した場合のS3内のゴミの後片付け

image.png

詳細

image.png
image.png

📝 Checksum vs Fingerprint

image.png

DD :two: "How do you prevent abuse?"

abuse = harmful/unintended ways like:

  • uploading malicious files like malware
  • uploading inappropriate content
  • uploading his personal irrelevant files (and lying about the file type)
  • uploading huge files (like TB) to drive up the storage cost

🟢 解決策1 Processing pipeline for file checks

Implement a processing pipeline

  1. Client uploads a file to a private quarantine bucket first.
  2. Run a job the file conntent check. If fails, mark it as REJECTED status.
    • virus scans
    • inappropriate content detection
    • file type validation
    • size checks
  3. Run a job to move the file to the public bucket, and update the database status to AVAILABLE.

As a bonus, this approch prevents someone from uploading malicious content and immediately sharing the link.

🟢 解決策2 File size limit in presigned URL

max file size limit を指定して、presigned URL を作る。

DD :three: "How do you handle metadata?"

Primary DB の中に metadata table を作り、そこに保存する。

  • upload_statusは、PENDING, UPLOADED, REJECTED, AVAILABLEをとる。
  • ファイルの object key は、uploads/{user_id}/{timestamp}/{uuid}にする。
    • これにより、CDC の Worker は CDC から、どのメタデータレコードの status を更新すればいいかが分かる。

📝 conditional update はとばした。

DD :four: "How do you ensure downloads are fast?"

🟢 解決策1. CDN を使う

CDN からファイルをここからダウンロードすれば良い。
private content に関しては、Signed CloudFront URL を使う。

TODO: Cache Header の指定

🟢 解決策2. HTTP Range Requests を使う

HTTP Range Requests を使う。
(S3 SDKでは内部でやってくれてる。)

これにより、concurrent & resumable downloads が可能。

image.png

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?