Recently, DidaOJ’s user base has started to grow, so I wanted to find a deployment approach that is as formal as possible while keeping costs acceptable.
Analysis
The following parts may need to be handled:
- Site static files
- User images
- Site web API
- Runtime programs
- Database
- Redis
- Judge service
- Runtime programs
- Judge data
- go-judge
Conclusion
The following services were ultimately chosen:
- Cloudflare R2
- User images
- Judge data
- Alibaba Cloud
- ECS
- Redis
- ECS
- Tencent Cloud
- EdgeOne
- Site static files
- Lighthouse
- Judge service runtime programs
- go-judge
- EdgeOne
Cloudflare R2 storage does not charge by traffic; instead, it charges by storage space and number of operations, making the cost extremely low at the current Page Views.
EdgeOne is being promoted by Tencent Cloud and offers a free site quota. In testing, its access speed in mainland China is considerably better than Cloudflare Pages.
Alibaba Cloud and Tencent Cloud each offer a discounted price for one instance, so they can be used to run long-running programs.
The web backend API uses Alibaba Cloud Function Compute, which is billed on a pay-as-you-go basis and is more stable than deploying directly on ECS.
For the database, Alibaba Cloud PostgreSQL was chosen, and the cost is currently fairly manageable.
Notes
DNS Proxy
Currently, the DNS records for the didapipa.com domain are hosted on Cloudflare. It provides a DNS proxy service that can convert HTTP sites to HTTPS and offers analytics and acceleration features.
However, in testing under the mainland China environment, this turned into a speed-reduction optimization, so the proxy is currently disabled and traffic goes directly to mainland Chinese cloud services.
In that case, however, SSL certificates need to be handled separately. A temporary one valid for 3 months has been applied for, and an automatic renewal mechanism still needs to be built.
Database
During this adjustment, the database was migrated from MySQL to PostgreSQL.
The motivation was that during earlier research, I found that Dify uses PostgreSQL. I had heard of it to some extent before but had never put it into practice. Taking this opportunity, I looked into it more deeply and found it quite usable. It is also an open-source and free product, so it can basically be used as a superior replacement for MySQL.
So after refactoring a batch of APIs, I migrated the entire database to Alibaba Cloud’s managed PostgreSQL, and it currently seems quite stable.
Speaking of which, since this system was completed, the database has been migrated quite a few times. Initially, MongoDB was chosen, and importing data from various systems was a real hassle.
Later, to reduce deployment costs, I chose to migrate to MySQL. During that process, I also did some field cleanup along the way, which led to scattered bugs that went unnoticed.
After this migration, it should not need to be touched again for the foreseeable short term.