Asynchronous malware scanning for public file submissions
Building an event-driven malware scanning pipeline on AWS.
Public file submissions needed malware scanning without slowing down the upload experience. Hamza engineered an event-driven AWS pipeline using S3, SQS, ClamAV and Celery, separating untrusted uploads from final storage and routing detected threats into quarantine.
- Role
- Software and backend engineer
- Client
- Department of Agriculture, Fisheries and Forestry (DAFF), Australia
- Engagement
- GoSource Australia (contract)
- Focus
- Event-driven architecture, distributed systems, asynchronous malware scanning
- Stack
- Python · Django · Celery · Amazon S3 · Amazon SQS · ClamAV · Event-driven architecture · Background workers
The problem
The Department operated a platform that accepted submissions from the public, and a submission could carry attachments: images, PDFs and other media. Every one of those files came from outside and had to be treated as untrusted until it had been scanned for malware.
Scanning inside the upload request would tie every response to however long the antivirus check took. Writing files straight into the application’s storage and scanning them later would put unscanned content inside the boundary the application trusts. Neither was acceptable.
The design
Hamza engineered a pipeline that separates three steps a simpler design would fuse together: accepting a file, deciding whether it is safe, and admitting it to the application.
Django accepts the submission and responds straight away. From there the file moves through dedicated S3 buckets, each with a single responsibility, and every hand-off is an S3 object-created event delivered through Amazon SQS to the component that acts next. A separate worker running ClamAV does the scanning; a Celery task in the Django backend does the final promotion.
Synchronous request
Public
Submitter
Images, PDFs, media
submits file
HTTP 200
Django
Submission API
Accepts the upload
The response does not wait for the scan.
HTTP 200 acknowledges the submission. It does not clear the file.
- stores upload
Amazon S3
Staging bucket
Unscanned files
- ObjectCreated
Amazon SQS
Scan queue
ObjectCreated events
- the scan worker consumes each message
Scan worker
ClamAV
An AWS-hosted worker retrieves and scans each staged file, then moves it by the result.
Clean
Amazon S3
Clean bucket
- notifies
Amazon SQS
Notification
- consumed
Celery
Promotion task
- promotes
Amazon S3
Final storage
Malware detected
Amazon S3
Quarantine
- notifies
Amazon SQS
Notification
- consumed
Django
Status processing
- surfaces
Application UI
Quarantined
- Upload and event flow
- HTTP response
- Clean path
- Malware path
How the pipeline worked
Accept, then acknowledge
A submitter uploads a file to the Django backend, which accepts the submission and returns HTTP 200 without waiting for antivirus processing. The response acknowledges receipt. It does not mean the file has been scanned or approved.
Stage and notify
The uploaded object lands in a dedicated S3 staging bucket. Its creation raises an S3 ObjectCreated event, which publishes a notification to an Amazon SQS queue.
Scan in an independent worker
An AWS-hosted worker consumes that queue, retrieves the staged file and scans it with ClamAV. Scanning runs entirely outside the Django request cycle.
Clean: promote through an intermediate bucket
When the scan is clean, the worker moves the file to a separate S3 clean bucket. Creating that object sends another SQS notification, which a Celery task in the Django backend consumes before moving the verified file into the application’s final storage bucket.
Malware detected: quarantine and report
When ClamAV identifies malware, the worker moves the file into a quarantine bucket instead. The quarantine path also produces an SQS notification, which the backend consumes so the application can show the file’s quarantined status in its UI.
Why the architecture matters
An immediate response keeps the upload experience independent of scanning. The submitter’s request finishes once the submission is accepted, and how long a scan takes no longer affects it.
S3 events and SQS decouple ingestion from scanning. Django does not call the scanner, and the scanner does not call Django: each side reacts to an object appearing in a bucket, with a queue holding the work in between. The worker and the backend operate independently, each consuming its own notifications.
Running ClamAV in its own AWS-hosted worker also keeps antivirus software and its workload out of the web application.
Trust boundaries, made explicit
Each bucket marks a state, not just a location. Staging holds files nobody has vouched for. The clean bucket holds files that passed the scan. Final storage holds only files that passed the scan and were then promoted by the backend. Quarantine holds files the scanner flagged.
The intermediate clean bucket is what keeps the scanner out of application storage. The worker’s job ends once it has placed a file in clean or quarantine; the move into final storage is made by the Django backend, in response to its own notification. Clearance by the scanner and admission by the application stay separate steps.
Files with detected malware take the other branch. They are moved into quarantine and do not enter application storage through this pipeline.
The invariant
Only files cleared by the scan, then promoted by the backend, reach final application storage through this pipeline.
Outside final storage · untrusted until cleared
Inside the application
Untrusted upload
Staging bucket
Accepted, not yet scanned. Held outside final storage.
Antivirus inspection
ClamAV worker
Scans each staged file and decides which path it takes.
Clean intermediate
Clean bucket
Passed the scan. Waits for the backend to promote it.
Quarantine
Quarantine bucket
Malware detected. The file stays here, isolated from application storage.
Final application storage
Final storage bucket
Receives files only from the clean path, by backend promotion.
Application UI
Quarantined status
The backend consumes the notification; the UI shows the file as quarantined.
Outside final storage · untrusted until cleared
Untrusted upload
Staging bucket
Accepted, not yet scanned. Held outside final storage.
Antivirus inspection
ClamAV worker
Scans each staged file and decides which path it takes.
Clean intermediate
Clean bucket
Passed the scan. Waits for the backend to promote it.
Quarantine
Quarantine bucket
Malware detected. The file stays here, isolated from application storage.
promoted by the backend
status only
Inside the application
Final application storage
Final storage bucket
Receives files only from the clean path, by backend promotion.
Application UI
Quarantined status
The backend consumes the notification; the UI shows the file as quarantined.
Results the application can show
Asynchronous processing still has to come back to the person who submitted the file. Both branches end in a notification the backend consumes: on the clean path, to promote the file; on the malware path, so the application can display the file as quarantined rather than leave its status unexplained.
The outcome
- Submissions accepted without waiting for a malware scan
- Clean files promoted into final application storage through an intermediate clean bucket
- Files with detected malware isolated in a quarantine bucket, outside application storage
- Quarantined status surfaced in the application’s UI
- Ingestion, scanning and promotion decoupled through S3 events, SQS and background workers
What it shows
Designing and delivering production backend systems with AWS messaging, storage events and background workers, and making a security-sensitive process asynchronous without blurring the line between checked and unchecked files.