<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tian Shijian</title>
    <description>The latest articles on DEV Community by Tian Shijian (@baytally).</description>
    <link>https://dev.to/baytally</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4273262%2Ff2ffb276-0248-49da-98b4-2408092cbd2d.png</url>
      <title>DEV Community: Tian Shijian</title>
      <link>https://dev.to/baytally</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/baytally"/>
    <language>en</language>
    <item>
      <title>How I run a multi-tenant SaaS on a single 1-core VPS with SQLite</title>
      <dc:creator>Tian Shijian</dc:creator>
      <pubDate>Mon, 30 Nov 2026 03:54:16 +0000</pubDate>
      <link>https://dev.to/baytally/how-i-run-a-multi-tenant-saas-on-a-single-1-core-vps-with-sqlite-4l21</link>
      <guid>https://dev.to/baytally/how-i-run-a-multi-tenant-saas-on-a-single-1-core-vps-with-sqlite-4l21</guid>
      <description>&lt;p&gt;I run a small SaaS for independent auto repair shops. One developer (me), one server, no DevOps help.&lt;/p&gt;

&lt;p&gt;The server: 1 vCPU, 2 GB RAM, Ubuntu. The whole application — web server, billing integration, email, nightly backups — runs as a single Python process using 38 MB of RAM.&lt;/p&gt;

&lt;p&gt;Here is how it holds together, and where I would stop doing it this way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The constraint that shaped everything
&lt;/h2&gt;

&lt;p&gt;I am not optimizing for scale. I am optimizing for "I can debug this alone at 11pm."&lt;/p&gt;

&lt;p&gt;Every piece of infrastructure I add is a piece I have to understand, upgrade, and pay for. So the question for every component was not "is this the best tool?" but "can I do without it?"&lt;/p&gt;

&lt;p&gt;That ruled out a lot.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two databases instead of one
&lt;/h2&gt;

&lt;p&gt;Most multi-tenant SaaS designs start with a single Postgres and a &lt;code&gt;tenant_id&lt;/code&gt; column on every table. I did the opposite: one control-plane database, and one SQLite file per shop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/opt/app/data/platform.db            # shops, users, subscriptions
/opt/app/data/stores/s001/store.db   # that shop's orders, inventory, staff
/opt/app/data/stores/s002/store.db
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Routing happens inside the request lifecycle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;store_db&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;store_key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"/opt/app/data/stores/{store_key}/store.db"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;getattr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"_db"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;row_factory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Row&lt;/span&gt;
        &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PRAGMA journal_mode=WAL"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PRAGMA busy_timeout=5000"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PRAGMA synchronous=NORMAL"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;

&lt;span class="nd"&gt;@app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;teardown_appcontext&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;getattr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"_db"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why this wins for my case:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Isolation is free.&lt;/strong&gt; One shop's corrupted file cannot affect another. And there is no &lt;code&gt;WHERE tenant_id = ?&lt;/code&gt; clause to forget.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Backup, export, or delete a tenant is one file operation.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A single shop is small.&lt;/strong&gt; 40 tables, 400 KB.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The cost: cross-tenant queries are awkward. I need exactly one — "how many shops are active" — and it is a loop over files, which is fine at this size.&lt;/p&gt;

&lt;h2&gt;
  
  
  WAL mode is not optional
&lt;/h2&gt;

&lt;p&gt;SQLite's write path is serialized. That sounds fatal for a web app, and it would be, except:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reads never block writes in WAL mode.&lt;/li&gt;
&lt;li&gt;A shop has maybe 3 to 8 people using it, doing a few dozen writes an hour. The write lock is held for microseconds.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The part people miss is &lt;code&gt;busy_timeout&lt;/code&gt;. Without it, a concurrent write returns &lt;code&gt;database is locked&lt;/code&gt; immediately instead of waiting. With &lt;code&gt;busy_timeout=5000&lt;/code&gt;, writers queue politely.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;PRAGMA synchronous=NORMAL&lt;/code&gt; is the other one. Full fsync on every commit is what makes people believe SQLite is slow. NORMAL with WAL is durable enough for this workload: you can lose the last few transactions on a power cut, not the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I deliberately did not install
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Postgres.&lt;/strong&gt; My entire data set is under 10 MB. The operational surface — connection pooling, vacuum, upgrades — costs more than it buys.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redis.&lt;/strong&gt; Nothing needs to survive between requests except sessions, and sessions live in SQLite.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Celery or any job queue.&lt;/strong&gt; The only background work is sending email and handling a payment webhook. Both finish in under a second, synchronously.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker.&lt;/strong&gt; systemd runs &lt;code&gt;python app.py&lt;/code&gt;. I skip a container layer, about 200 MB of overhead, and one more thing that can fail at 3am.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A load balancer or multiple workers.&lt;/strong&gt; One process. Load average: 0.00.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is the whole stack. Memory usage: 38 MB.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trap nobody warns you about: time zones
&lt;/h2&gt;

&lt;p&gt;The server sits in one timezone. Customers do not.&lt;/p&gt;

&lt;p&gt;A repair order closed at 11:58pm local time must show up in &lt;em&gt;that shop's&lt;/em&gt; "today", not the server's tomorrow. So every shop stores its own IANA timezone, and every business-date calculation goes through it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;zoneinfo&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ZoneInfo&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;today_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;store_tz&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ZoneInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;store_tz&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;"America/New_York"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every "today's sales", "this week's payroll", "overdue orders" query uses that function. It is a one-line fix that prevents months of "your report is off by a day" support tickets, and it stays invisible until a customer in a different timezone signs up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Backups are the whole ballgame
&lt;/h2&gt;

&lt;p&gt;When your database is a file, backup is a file copy. But not &lt;code&gt;cp&lt;/code&gt; — copying a live WAL database gives you a torn snapshot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sqlite3 store.db &lt;span class="s2"&gt;"VACUUM INTO '/tmp/snap.db'"&lt;/span&gt;
rclone copy /tmp/snap.db remote:backups/&lt;span class="nv"&gt;$(&lt;/span&gt;date +%F&lt;span class="o"&gt;)&lt;/span&gt;/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;VACUUM INTO&lt;/code&gt; writes a consistent, compacted copy while the app keeps running. Then &lt;code&gt;rclone&lt;/code&gt; ships it to WebDAV storage off-site. Cron, once a night.&lt;/p&gt;

&lt;p&gt;A backup you have never restored is a rumor, so I run a restore drill: unzip, point the service at the file, restart. It takes about 40 seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Billing webhooks
&lt;/h2&gt;

&lt;p&gt;Paddle handles payments as merchant of record. The webhook is the one place where I do care about correctness:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verify the HMAC signature before parsing anything.&lt;/li&gt;
&lt;li&gt;Look up the shop by &lt;code&gt;custom_data.store&lt;/code&gt;. If a renewal arrives without it, fall back to &lt;code&gt;subscription_id&lt;/code&gt; or &lt;code&gt;customer_id&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Treat the event as idempotent: the same event ID processed twice must not double-extend a subscription.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That fallback matters. Subscription renewals often carry no &lt;code&gt;custom_data&lt;/code&gt;. Before I added the lookup, a renewal would return 400 — money taken, plan not extended.&lt;/p&gt;

&lt;h2&gt;
  
  
  When I would move to Postgres
&lt;/h2&gt;

&lt;p&gt;Honestly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A single tenant with 50+ concurrent users, where SQLite's single writer becomes the bottleneck.&lt;/li&gt;
&lt;li&gt;Reporting that constantly needs to join across all tenants.&lt;/li&gt;
&lt;li&gt;Data past a few tens of GB per tenant.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of those are true today. At 400 KB per shop, this box has room for thousands of tenants before disk becomes the conversation.&lt;/p&gt;

&lt;h2&gt;
  
  
  The point
&lt;/h2&gt;

&lt;p&gt;Total infrastructure: one VPS, one Python process, 38 MB of RAM, load average 0.00.&lt;/p&gt;

&lt;p&gt;If your SaaS serves a few hundred small businesses doing a few dozen writes an hour, SQLite is not a compromise you will grow out of next month. It is the correct answer for the constraints you actually have. The hard part is not the database. It is knowing which problems you do not have yet.&lt;/p&gt;

&lt;p&gt;Site: &lt;a href="https://baytally.app" rel="noopener noreferrer"&gt;https://baytally.app&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sqlite</category>
      <category>saas</category>
      <category>flask</category>
      <category>python</category>
    </item>
    <item>
      <title>I built a back office for independent auto shops — here is what 30 owner conversations taught me</title>
      <dc:creator>Tian Shijian</dc:creator>
      <pubDate>Mon, 30 Nov 2026 03:29:25 +0000</pubDate>
      <link>https://dev.to/baytally/i-built-a-back-office-for-independent-auto-shops-here-is-what-30-owner-conversations-taught-me-283m</link>
      <guid>https://dev.to/baytally/i-built-a-back-office-for-independent-auto-shops-here-is-what-30-owner-conversations-taught-me-283m</guid>
      <description>&lt;p&gt;I'm not a mechanic. I'm a developer who spent the last few months talking to independent auto shop owners, and I kept hearing the same three sentences.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. "I know my labor rate. I don't know what a job actually made."
&lt;/h2&gt;

&lt;p&gt;Almost every owner can quote their door rate instantly. Almost none can tell you what the last ten jobs netted after parts cost and technician pay.&lt;/p&gt;

&lt;p&gt;On a $289 brake job with $45 in pads and 0.8 flat-rate hours paid to a tech, the margin looks very different from what the invoice suggests. Owners feel this intuitively — they just can't see it per ticket.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. "Payroll is where I find out what my techs really earn."
&lt;/h2&gt;

&lt;p&gt;Flat rate means a tech's effective hourly rate moves every week. Most shops only discover it on payday, after the work is already sold. By then it's too late to fix the pricing.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. "Money leaks in places nobody is watching."
&lt;/h2&gt;

&lt;p&gt;Unpaid repair orders sitting for weeks. Discounts applied at the counter that nobody approved. Parts cost drifting upward while sale prices stay flat. None of these show up in a monthly P&amp;amp;L in time to act.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;BayTally is a small back-office tool that sits next to whatever DMS the shop already uses. It does four things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;True parts cost per RO&lt;/strong&gt; — cost, not retail, with a reorder point per part&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flat-rate earnings per tech, per job&lt;/strong&gt; — effective hourly rate, updated as work is closed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Owner alerts&lt;/strong&gt; — unpaid ROs, discounts without approval, margin drops&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A printable RO and a daily drawer count&lt;/strong&gt; — because the front counter still runs on paper half the time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's deliberately not a full DMS. Shops don't rip out their DMS for a new tool; they bolt one on when it answers a question the DMS can't.&lt;/p&gt;

&lt;h2&gt;
  
  
  A concrete example
&lt;/h2&gt;

&lt;p&gt;One shop I worked with had a $159 open RO that had been sitting for 19 days. Nobody had called the customer. That's not a software problem — it's a visibility problem. A one-line alert would have caught it on day two.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pricing, plainly
&lt;/h2&gt;

&lt;p&gt;$49/month for inventory, tech pay and alerts. $79/month adds the front counter: ROs, cashier, daily close, accounting export. 7-day trial, no card required.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd like from you
&lt;/h2&gt;

&lt;p&gt;If you run an independent shop — or know someone who does — I'd genuinely like to hear which of the three problems above hurts most. I'm not trying to sell in the comments; I'm trying to find out which feature to build next.&lt;/p&gt;

&lt;p&gt;Site: &lt;a href="https://baytally.app" rel="noopener noreferrer"&gt;https://baytally.app&lt;/a&gt;&lt;/p&gt;

</description>
      <category>saas</category>
      <category>business</category>
      <category>productivity</category>
      <category>startup</category>
    </item>
  </channel>
</rss>
