Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Figma 24 min read Case study mediumAdept

How we built a custom permissions DSL at Figma

Figma replaced a sprawling Ruby `has_access?` permissions function with a custom, JSON-serializable permissions DSL and a cross-platform policy engine, inspired by AWS IAM policies. Each policy declares a resource type, an allow/deny effect, granular permissions and boolean conditions written as ExpressionDef triples that reference data fields such as `file.deleted_at`. Because policies are pure data, the same rules run in both the Ruby/Sinatra backend and the TypeScript LiveGraph realtime layer, and data dependencies can be extracted statically. That separation decouples policy logic from data loading, letting rules be written and debugged independently and reducing database load from permission checks, which had been about 20% of total load.

Related posts

  • Visibility at scale: How Figma detects sensitive data exposure

    Figma mediumAdept

    Figma built Response Sampling, a detection layer that randomly samples outbound API responses and checks them for sensitive data the requesting user shouldn't see. The first version ran as an `after` filter in Figma's Ruby application server. It extracted high-entropy file identifiers from JSON bodies and verified access asynchronously against PermissionsV2, and LiveGraph fed in its own samples through an internal endpoint. The expanded version uses FigTag column annotations (`banned_from_clients`) and ActiveRecord callbacks to record the sensitive values loaded during a request, then flags any of them that appear in the serialized response. Sampling, async checks, rate limiting, dynamic allowlists and running in both staging and production kept latency and false positives under control while surfacing real authorization gaps.

  • Higher-level CRUD Abstraction for Postgres RLS

    Neon mediumAdept

    Postgres Row-Level Security requires separate USING and WITH CHECK policies per operation, which gets repetitive for CRUD apps. Neon's Drizzle ORM helper `crudPolicy` takes a role plus `read` and `modify` expressions (true, false, a SQL expression, or null to skip) and generates the select, insert, update and delete policies. A companion `authUid` helper ties pg_session_jwt's `auth.user_id()` to a table column. The post shows the raw SQL for a todos table next to the equivalent concise Drizzle schema. The functionality has since moved into the Neon Data API.

  • Modelling Authorization for a Social Network with Postgres RLS and Drizzle ORM

    Neon mediumAdept

    Postgres Row-Level Security can express the full authorization model for a Twitter-like social network, defined with Drizzle ORM's crudPolicy and pgPolicy helpers and the pg_session_jwt extension's auth.user_id(). Profiles, posts and comments get simple policies: public reads, owner-only writes. Private chats need more care: participants can only see other participants of their own chats, a self-referential rule RLS can't express without recursion errors, so it lives in a view made read-only by adding DISTINCT. Takeaways are that raw-SQL RLS is error-prone, testing policies is hard, schemas exposed to the frontend need careful design beyond policies (e.g. unique constraints), and this work shouldn't be trusted to an LLM.

  • A tale of two parameter architectures—and how we unified them

    Figma mediumAdept

    Figma replaced the separate architectures behind component properties (scoped, layer-level parameters) and variables (global, library-level parameters) with one parametrization system. At the data model level, both systems now share a single parameter typespace and a single binding store, so each layer property can bind to at most one parameter and cross-system bindings such as component property to variable become possible. At runtime, every parameter system follows the same pipeline: usage tracking, property-level invalidation, transitive resolution across aliases and system boundaries, and a consolidated update/re-render path. That shared foundation is meant to support future parameter systems such as a CMS without rebuilding binding infrastructure.

  • How Figma manages sandboxes at scale

    Figma mediumAdept

    Nimbus is Figma's internal platform for running tens of thousands of sandboxes for AI-generated code across multiple cloud providers. Teams declare a namespace config (image, resources, health checks, warm pool bounds, allowed hosts), and a control plane picks providers, enforces egress policy and manages lifecycle through GetOrCreate, Get and Delete APIs. Security comes from read-only egress to untrusted hosts, enforced by provider controls or a proxy sidecar, plus encrypted credentials that are swapped for real ones only at the intended destination. Demand-sized warm pools with Postgres skip-locked claiming, health-weighted provider routing and Redis-scheduled health checks cut provisioning latency by 90% and raised availability from 99% to 99.95%. A control-loop simulator exposed a feedback bug where slow-but-successful providers kept receiving work.

The quest for software engineering knowledge.

Look:
Layout: