# Dali's DAL - Designing a Data Access Layer Like an Artist

- Speaker: [Inbal Levy](/wiki/speakers/inbal-levy.md)
- Event: [Reversim Summit 2025](/wiki/years/2025.md)
- Video: https://www.youtube.com/watch?v=_yV5t-lLlmU
- Transcript: [/transcripts/2025/55-_yV5t-lLlmU.md](/transcripts/2025/55-_yV5t-lLlmU.md)
- Language: Hebrew · Type: talk · Level: intermediate
- Topics: [Databases](/wiki/topics/databases.md), [Architecture](/wiki/topics/architecture.md), [Software Engineering](/wiki/topics/software-engineering.md), [Testing](/wiki/topics/testing.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

The speaker explores the evolution of designing a data access layer by comparing it to surrealist art, specifically the works of Salvador Dali. The talk details a real-world journey from a simple ORM-based repository pattern to handling complex analytical queries using raw SQL with advanced patterns like query builders and strategy patterns. Through these examples, the audience learns how to balance clean architecture principles with the practical realities of growing a backend system and managing databases efficiently.

## Key points

- [2:08](https://www.youtube.com/watch?v=_yV5t-lLlmU&t=128s) The speaker introduces the core concept of a data access layer, separating business logic from database interactions to allow independent evolution.
- [5:32](https://www.youtube.com/watch?v=_yV5t-lLlmU&t=332s) A well-designed data access layer consists of four main ingredients: data storage representation, a business interface, query building and data processing, and connection management.
- [8:45](https://www.youtube.com/watch?v=_yV5t-lLlmU&t=525s) The team initially started with the classic repository pattern using an ORM to map database tables directly to application code without writing raw SQL.
- [11:04](https://www.youtube.com/watch?v=_yV5t-lLlmU&t=664s) Using hexagonal architecture with fake adapters instead of mocks allowed the team to run fast, reliable tests in-memory without spinning up heavy database infrastructure.
- [16:45](https://www.youtube.com/watch?v=_yV5t-lLlmU&t=1005s) As the system transitioned to analytical workloads that standard ORMs could not support, the team shifted to writing raw SQL queries.
- [21:15](https://www.youtube.com/watch?v=_yV5t-lLlmU&t=1275s) Managing dozens of raw SQL queries for different data cuts and percentiles proved unmaintainable when schema migrations occurred.
- [22:22](https://www.youtube.com/watch?v=_yV5t-lLlmU&t=1342s) The team introduced query builders and fluent interfaces to reuse query logic and simplify database interactions.
- [24:37](https://www.youtube.com/watch?v=_yV5t-lLlmU&t=1477s) A strategy pattern was implemented to dynamically select the most efficient database table or materialized view based on the specific request context.

## Takeaways

- Start with simple patterns like the repository pattern and ORMs when building a new system, but be ready to adapt as complexity grows.
- Implement fake adapters instead of database mocks to write fast, maintainable unit tests.
- Use design patterns like query builders and strategy patterns to reduce code duplication when dealing with complex raw SQL queries.
- Choose your data storage technology based on your analytical requirements, keeping in mind the trade-offs in development cost.

## Questions this talk answers

- When should a backend system transition from an ORM-based repository pattern to raw SQL and OLAP databases?
- How can you implement fast in-memory tests for database-heavy applications using hexagonal architecture?
- What design patterns can help manage and reuse complex raw SQL queries across multiple analytical views?

## Technologies

PostgreSQL, Prisma, ClickHouse, Kafka, SQS

## Tags

architecture, backend, data access layer, design patterns, orm, sql, testing
