SQLite Recursive CTE Powers Novel Ray Tracer Implementation

@simonw· July 13, 2026 View original

▶ The 60-second brief

Summary

A new project demonstrates a ray tracer built entirely using SQLite's recursive Common Table Expressions, storing its state on disk. This unique approach allows other tools to query the ray tracer's state in real-time, exemplified by a custom HTML+JS minimap.

A developer has showcased an innovative ray tracer implementation that leverages SQLite's recursive Common Table Expressions (CTEs). This unconventional method allows the ray tracer to render frames by performing complex calculations directly within the database. The system's state is persistently stored within the SQLite database on disk. This design choice enables external applications to interact with and query the ray tracer's current state dynamically. As a practical example, the creator developed a custom HTML and JavaScript-based minimap that can access and display the ray tracer's internal data while it is actively running.

Why it matters

This demonstrates creative and unexpected uses for established database technologies, potentially inspiring novel architectural patterns for data-driven applications or simulations. It highlights how existing tools can be pushed beyond their conventional boundaries.

How to implement this in your domain

  1. 1Explore using recursive CTEs in SQL for complex data processing or simulations beyond typical data retrieval.
  2. 2Investigate SQLite's capabilities for persistent state management in lightweight, embeddable applications.
  3. 3Design systems where core application state is exposed via a database, enabling real-time external tool integration.
  4. 4Experiment with building custom visualization or monitoring tools that directly query application databases.

Who benefits

Software DevelopmentGamingData VisualizationEducation

Key takeaways

  • SQLite recursive CTEs can be used for complex computational tasks like ray tracing.
  • Storing application state in a database enables real-time external querying and integration.
  • Creative use of existing technologies can lead to novel and efficient solutions.
  • This approach offers new possibilities for data-driven simulations and interactive tools.

Original post by @simonw

"This is really cool! It renders frames using a ray tracer implemented as a SQLite recursive CTE Since state is stored in a SQLite database on-disk you can have other tools query it while you are playing - I rolled this custom HTML+JS view that adds a minimap"

View on X
SQLite Recursive CTE Powers Novel Ray Tracer Implementation

Originally posted by @simonw on X · view source

Want to go deeper?

Turn these trends into skills with Learnijoy's hands-on AI & tech courses.

Explore courses