r/learnSQL • • 21m ago

I am building sql learning platform? I have few douts could plz suggest me best one

I'm building a SQL learning platform (similar to SQL learning playgrounds) where users can write and execute SQL queries directly in the browser.

I'm exploring different approaches to handle SQL query execution while ensuring that one user's queries never affect another user's database or the original lesson dataset.

I've considered three approaches so far:

Database Transactions: Execute every user's query inside a transaction and use ROLLBACK after execution so that changes such as INSERT, UPDATE, and DELETE are not permanently saved.

Transaction Isolation Levels: Use PostgreSQL isolation levels to prevent concurrent users from interfering with each other's queries or data.

Separate Database Instances/Schemas: Create an isolated database environment for each user, seed it with the required lesson dataset, execute their queries, and reset or destroy the environment afterward.

My questions:

Which approach would you recommend for a production-ready SQL learning platform?

Are transactions with ROLLBACK sufficient, or are there limitations?

Would creating a separate database or schema for each user be too expensive when hundreds of users execute queries concurrently?

How do platforms like SQL playgrounds handle query isolation and concurrent execution?

Is there a better architecture, such as temporary databases, connection pooling, containers, or PostgreSQL snapshots?

Expected scale: Initially, around 100 concurrent users, with the possibility of scaling further.

I'm using Node.js, Express, PostgreSQL, Redis, and BullMQ for asynchronous query execution.

I'd appreciate suggestions based on real-world experience and trade-offs. Thanks!

0 Upvotes

3 comments sorted by

2

u/lolcrunchy 13m ago

If you check this subs history you'll have hundreds of examples of sql learning platform solo projects to copy features from.

1

u/leogodin217 5m ago

A lot of people doing this today use WASM to run the queries in the user's browser with the user's local resources. Here's a quick example using DuckDB. https://github.com/leogodin217/nhs_sql_practice_data. Claude built the WASM stuff in probably a couple hours including my testing and interaction, so the mechanisms are pretty easy.

If you go this route, you'd probably still need a hosted DB for your use case, but it wouldn't be running user queries.