Series AIB10 Deck Log

~5 min read

The Single-Server Infrastructure Behind AIB10

A record of the now-retired AIB10's infrastructure. One server, one container, and one SQLite file served both the web app and the Chrome extension. Mail was sent and received through SES, and bounced addresses were blocked automatically. Fixed cost was about 25 dollars a month. At shutdown the data was backed up and the resources deleted.

ProjectInfrastructureAWSEmail

The whole picture

AIB10 ran on a single server. The web app and the Chrome extension called the same backend, and the backend was one container. The processing logic is covered in Logic Design and the screens in Features and Screens.

Browser · Chrome extension
      │ HTTPS
      ▼
Route 53 (aib10.com)
      │
      ▼
One EC2 instance (Amazon Linux 2023, Seoul region)
 ├─ Nginx :80/:443   Let's Encrypt certificate
 └─ Docker Compose
     └─ One container (uvicorn + FastAPI, 127.0.0.1:8000)
         ├─ Scheduler thread
         └─ SQLite file (host volume)

Outbound calls     NAVER API HUB · Gemini · SES SMTP
Inbound mail       MX → SES → S3 → Lambda → operator's mailbox
Bounces/complaints SES → SNS → server webhook
Automation         3 GitHub Actions workflows (tests · retraining · list refresh)

Server and container

The server was one EC2 t3.small with a fixed IP attached. Nginx takes ports 80 and 443 and passes requests to port 8000 of the container. The container port was opened only on the server's internal address. If unencrypted requests reached the app directly, secure-cookie login would fail and request headers could be spoofed.

There is one container, and one uvicorn process inside it. The search cache and suggested keywords live in process memory, and the scheduler is a thread of the same process. Adding processes would split the cache and run the scheduler more than once. So this setup assumes a single process. Container memory was capped at 2GB, to keep TensorFlow from using all of the server's memory when it loads the model. The container is health-checked every 30 seconds and runs as an account without administrator rights.

Three configuration problems came up in operation.

  • After the container was switched to an account without administrator rights, the owner of the data folder no longer matched. The SQLite file could not be opened and the container kept restarting. It was resolved by changing the folder's owner to the container account.
  • The trusted-proxy address setting used range notation, which uvicorn 0.30 did not support. It was ignored without an error, and every request was recorded with the proxy's IP. Per-IP rate limits were being summed as if for one person. It was fixed by writing the Docker network's gateway address literally.
  • Standard output was buffered under Docker, so the configuration check at startup did not show in the logs. Output built to surface problems early was not reaching the operator. An environment variable that turns off output buffering was added to the image.

Data and backups

The data is in a single SQLite file. The file was stored by mounting a host folder into the container. Without that mount, the accumulated time series and accounts would disappear whenever the container was recreated. Schema changes are applied automatically when the app starts. So before every deployment the DB file and the environment file were copied with a date attached. No scheduled automatic backup was built.

Deployment

The repository was private and the server held no credentials for it. Deployment packed only the tracked files locally and sent them over SSH.

git archive --format=tar HEAD | ssh <server> "tar -x -C ~/aib10"
ssh <server> "cd ~/aib10 && docker compose up -d --build"

Only tracked files are transferred, so the server's environment file and data folder are left untouched. The omissions that happened when copying files one by one also went away. After the environment file changed, the container had to be force-recreated for the values to take effect. No automated deployment was built. The last deployment was on September 9, and the overseas news and English screens made after that never reached the server.

Certificates

Certificates came from Let's Encrypt. In June a certificate expired. The cause was that the certificate tool had been installed with pip and not the package manager, so the automatic renewal timer had never existed. On September 3 a renewal service and timer were registered by hand. After that, renewal was attempted twice a day.

Sending mail

Mail was sent through Amazon SES over SMTP. The sending credentials belonged to a separate account that held only the permission to send mail. DKIM signing, SPF, and DMARC records were registered on the domain.

A new SES account starts in a restricted state where it can send only to verified addresses. During that time the service ran in a mode that saved mail as files on the server. The screen was then telling users that unsent mail had been sent, and the wording was fixed in September. The request to lift the restriction included sending frequency, how recipients are managed, how bounces are handled, and actual mail samples. Approval came on September 9, allowing up to 50,000 messages a day.

After approval the file-saving mode was turned off, so that a deployment with missing settings surfaces as an error and does not quietly pile mail up as files. The order of setup was fixed as well. The SMTP address goes in after approval. Doing it the other way round, with the address entered before approval, once blocked all login mail.

Handling bounces and complaints

Continuing to send to bounced addresses lowers sender reputation. On a permanent bounce or a spam complaint, mail to that address is turned off automatically.

Mail sent (with a configuration set)
  → SES publishes bounce and complaint events
  → SNS topic
  → Server webhook
  → Mail to that address turned off

The webhook is an address open without authentication. So both the SNS signature and the sending topic are verified. If the topic setting is empty, every event is rejected. Transient bounces are not acted on, to avoid cutting off users whose mailbox was briefly full. The behavior was confirmed with the test addresses SES provides, which affect neither billing nor reputation.

Receiving mail

The site listed addresses for inquiries and privacy inquiries. But the domain had no inbound setup, so those addresses could not receive mail. The inbound path was built on September 3.

MX record → SES receipt rule → S3 (auto-deleted after 30 days) → Lambda → operator's mailbox

The Lambda filters out mail flagged as spam or virus and forwards the rest to the operator. On forwarding, the sender is replaced with the service address and the original sender is put in the reply-to address. Leaving the original sender in place breaks sender authentication and the mail is classified as spam. The cost was calculated at about 0.03 dollars for 100 messages a month. The other inbound product that the console recommends carries a 50-dollar monthly subscription and was not used.

Automation

There were three GitHub Actions workflows.

WorkflowScheduleWhat it does
TestsEvery PRRuns lint and the 489 tests
Sentiment dataset growth and retrainingEarly every MondayCollects news titles, labels with Gemini, retrains, checks quality, commits
Listed-company list refreshStart of each monthDownloads the KRX list, rejects a shrunken result, records companies added and removed

The retraining workflow checks how much better the new model is than constant prediction. If it falls short, only the model is rolled back to the previous one and the added data is kept. In August this workflow failed 5 times in a row because credentials had not been registered, and it went unnoticed for a while. There was no path that reported failures.

Observability and cost

No monitoring tool was set up. What could be seen was the Nginx access log, the container log, and operator commands that query the DB. Only 10 days of access logs were kept. Seeing whether there were users required connecting to the server, and that check happened about once a month.

Fixed cost is estimated at about 25 dollars a month. Most of it is the cost of the one server.

The order of teardown

On November 26 things were cleaned up in the following order.

  1. A final copy of the DB was made and its integrity checked. It was archived together with the environment file, the Nginx configuration, and earlier backups, and kept locally.
  2. The server and disk, the fixed IP, the firewall rules, and the access key were deleted.
  3. The mail resources were deleted: the SES domain identity and configuration set, the receipt rule, the SNS topic, the Lambda, the S3 bucket, and the sending account.
  4. The web address and DKIM records were removed from DNS.
  5. The extension was unpublished from the Chrome Web Store.

The domain was kept and not deleted. If it lapsed, someone else could register it and use the old links and mail addresses. Only settings declaring that the domain sends no mail were left.

RecordValueMeaning
MX0 .This domain does not receive mail
SPFv=spf1 -allNo server sends for this domain
DMARCp=rejectMail that fails authentication is rejected

Looking back

Key point

One server and one file database were enough for the scale of this service. What was lacking was observability. There was nowhere to see user counts, send counts, and workflow failures every day. The workflow was noticed after 5 failures and the certificate after it had expired. Even the fact that there were no users was learned only by connecting to the server.

On the next project, the place to see the key numbers and failure alerts gets built on the day the server goes up.

Related

Portfolio'AIB10' — AI News Summarization & Sentiment AnalysisOperationsAIB10 — AI-powered news summarization and sentiment analysisJournalAIB10's Logic Design, from Collection to AlertsJournalThe Features and Screens That Went Into AIB10JournalEnding AIB10, and the 80 Days Without a Single Sign-upJournalThe Three Weeks AIB10's Sentiment Model First Beat Constant Prediction

2 more — see all under AIB10 in Operations ›