Cloudflare has several free services can use. Cloudflare D1 let you build a small database on Cloudflare’s server. Cloudflare worker is a free compute resource, you can write several script to call api. The most important thing is these service are free. For a free tier account you can access 5GB space in D1 database, Workers provides 100,000 requests per day.

The comment system can be devided to three different components.

  • Blog frontend
    • renders and display comments using HTML and JavaScript
  • Cloudflare worker
    • manages the api request from user
  • Cloudflare D1
    • stores and queries comment data
	+-------------------------------------------------------------+
	|                      USER / BROWSER                         |
	|  - Renders Blog Page                                        |
	|  - Submits new comment or fetches existing comments         |
	+------------------------------+------------------------------+
	                               |
	                               |  HTTPS (REST API Call)
	                               |  GET /POST /api/comments
	                               v
	+-------------------------------------------------------------+
	|               CLOUDFLARE WORKER (Serverless)                |
	|  - Routing & Logic Handler                                  |
	+------------------------------+------------------------------+
	                               |
	                               |  
	                               |  
	                               v
	+-------------------------------------------------------------+
	|               CLOUDFLARE D1 (Serverless SQLite)             |
	|  - Stores: id, post_slug, author, content, created_at       |
	+-------------------------------------------------------------+

future optimization:

  • add limit rate and bot protection