<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/multitenancy-with-arconia-and-spring-security-oauth-pt-2--7ra0zlua7" -->

---
title: Multitenancy with Arconia and Spring Security OAuth (pt 2)
description: A hands-on walkthrough builds on a previous multi-tenancy demo using Arconia and Spring Security OAuth, moving from an authentication-only setup to actually...
canonical: https://daily.dev/posts/multitenancy-with-arconia-and-spring-security-oauth-pt-2--7ra0zlua7
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Multitenancy with Arconia and Spring Security OAuth (pt 2) | daily.dev
og:description: A hands-on walkthrough builds on a previous multi-tenancy demo using Arconia and Spring Security OAuth, moving from an authentication-only setup to actually...
og:url: https://daily.dev/posts/multitenancy-with-arconia-and-spring-security-oauth-pt-2--7ra0zlua7
og:image: https://api.daily.dev/og/posts/7ra0zlUa7.png
og:image:alt: Multitenancy with Arconia and Spring Security OAuth (pt 2)
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Multitenancy with Arconia and Spring Security OAuth (pt 2)

**[Coffee \+ Software](https://daily.dev/sources/coffee-software)** · 50 min read · 0 upvotes · 0 comments

## Summary

A hands-on walkthrough builds on a previous multi-tenancy demo using Arconia and Spring Security OAuth, moving from an authentication-only setup to actually partitioning tenant data. The session sets up a Spring Cloud Gateway to route requests to a backend API and static frontend, then implements two data-partitioning strategies: a dedicated database per tenant (using a Docker-based registry to provision Postgres containers and a delegating data source) and a schema-per-tenant approach (using a bean post-processor to wrap the auto-configured data source and set the schema per connection). Flyway-based data source initializers handle migrations per tenant, with caching to avoid redundant work. Row-level security is mentioned as a third, less favored option due to invasiveness and noisy-neighbor issues. The demo concludes with both approaches working against real Postgres containers, showing tenant-isolated customer data.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=Qk1x6ugyZVU>

## Questions this post answers

### What are the main strategies for isolating tenant data in a multi-tenant Spring Boot application backed by PostgreSQL?

Three approaches exist: a dedicated database per tenant, a dedicated schema per tenant within one PostgreSQL instance, and row-level security using a tenant ID column with a session variable. Database-per-tenant gives the strongest isolation but is the most expensive; schema-per-tenant balances isolation and cost using a single data source with schema switching; row-level security is minimally invasive but suffers from noisy-neighbor problems.

_Developers weighing tenant isolation trade-offs can compare these implementation patterns on daily.dev._

### How can I switch PostgreSQL schemas per tenant on an existing Spring Boot data source without creating a new connection pool per tenant?

Wrap the auto-configured data source with a custom DelegatingDataSource whose getConnection method calls connection.setSchema() using the current tenant identifier from the tenant context, then delegates to the underlying connection. A Spring BeanPostProcessor intercepts the existing DataSource bean at startup and substitutes this schema-aware wrapper, so only one connection pool is needed while each tenant's queries run against its own schema.

_Engineers implementing schema-per-tenant isolation in Spring Boot can dig into this pattern on daily.dev._

### Why should a JWT access token not be exposed directly in the browser for a web client that talks to a backend API?

Storing or handling the JWT in browser JavaScript is less secure and requires more code than relying on a server-side session tied to a cookie. Routing both the static frontend and backend API through a single gateway (e.g., Spring Cloud Gateway) lets the gateway hold the authenticated session in memory, attach the token to downstream requests itself, and avoid CORS issues since everything is served from the same domain.

_Anyone architecting secure session handling for a gateway-backed frontend can explore this reasoning on daily.dev._

## Similar posts on daily.dev

- [Implement Multitenancy in Spring Authorization Server](https://daily.dev/posts/implement-multitenancy-in-spring-authorization-server-ts9wg4fgx) · Baeldung · 2 upvotes · 0 comments
- [Tenant Isolation in Multi-Tenant Systems: Architecture, Identity, and Security](https://daily.dev/posts/tenant-isolation-in-multi-tenant-systems-architecture-identity-and-security-epsekbshh) · Security Boulevard · 1 upvotes · 0 comments
- [Why I prefer multi-tenant systems](https://daily.dev/posts/why-i-prefer-multi-tenant-systems-gratprt4l) · Advanced Web Machinery · 95 upvotes · 4 comments
- [Build a Multi-Tenant Saas API with NestJS and Postgres](https://daily.dev/posts/build-a-multi-tenant-saas-api-with-nestjs-and-postgres-weolds5ch) · Telerik · 0 upvotes · 0 comments

---

Tags: [#java](https://daily.dev/tags/java), [#postgresql](https://daily.dev/tags/postgresql), [#spring-security](https://daily.dev/tags/spring-security)

[View this post on daily.dev](https://daily.dev/posts/multitenancy-with-arconia-and-spring-security-oauth-pt-2--7ra0zlua7)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Multitenancy with Arconia and Spring Security OAuth (pt 2)","url":"https://daily.dev/posts/multitenancy-with-arconia-and-spring-security-oauth-pt-2--7ra0zlua7","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/multitenancy-with-arconia-and-spring-security-oauth-pt-2--7ra0zlua7"},"datePublished":"2026-08-29T22:28:48.972Z","dateModified":"2026-09-14T09:11:16.335Z","description":"A hands-on walkthrough builds on a previous multi-tenancy demo using Arconia and Spring Security OAuth, moving from an authentication-only setup to actually...","image":"https://i.ytimg.com/vi/Qk1x6ugyZVU/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/Qk1x6ugyZVU/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Coffee + Software","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Coffee + Software","logo":"https://media.daily.dev/image/upload/s--nAGLloYn--/f_auto,q_auto/v1773648811/logos/coffee-software?_a=BAMAMiiu0","url":"https://daily.dev/sources/coffee-software"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/multitenancy-with-arconia-and-spring-security-oauth-pt-2--7ra0zlua7","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"java,postgresql,spring-security","timeRequired":"PT50M","video":{"@type":"VideoObject","name":"Multitenancy with Arconia and Spring Security OAuth (pt 2)","description":"A hands-on walkthrough builds on a previous multi-tenancy demo using Arconia and Spring Security OAuth, moving from an authentication-only setup to actually...","thumbnailUrl":"https://i.ytimg.com/vi/Qk1x6ugyZVU/sddefault.jpg","uploadDate":"2026-08-29T22:28:48.972Z","duration":"PT50M","url":"https://api.daily.dev/r/7ra0zlUa7","embedUrl":"https://www.youtube.com/embed/Qk1x6ugyZVU"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Coffee + Software","item":"https://daily.dev/sources/coffee-software"},{"@type":"ListItem","position":3,"name":"Multitenancy with Arconia and Spring Security OAuth (pt 2)"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/multitenancy-with-arconia-and-spring-security-oauth-pt-2--7ra0zlua7#faq","mainEntity":[{"@type":"Question","name":"What are the main strategies for isolating tenant data in a multi-tenant Spring Boot application backed by PostgreSQL?","acceptedAnswer":{"@type":"Answer","text":"Three approaches exist: a dedicated database per tenant, a dedicated schema per tenant within one PostgreSQL instance, and row-level security using a tenant ID column with a session variable. Database-per-tenant gives the strongest isolation but is the most expensive; schema-per-tenant balances isolation and cost using a single data source with schema switching; row-level security is minimally invasive but suffers from noisy-neighbor problems. Developers weighing tenant isolation trade-offs can compare these implementation patterns on daily.dev."}},{"@type":"Question","name":"How can I switch PostgreSQL schemas per tenant on an existing Spring Boot data source without creating a new connection pool per tenant?","acceptedAnswer":{"@type":"Answer","text":"Wrap the auto-configured data source with a custom DelegatingDataSource whose getConnection method calls connection.setSchema() using the current tenant identifier from the tenant context, then delegates to the underlying connection. A Spring BeanPostProcessor intercepts the existing DataSource bean at startup and substitutes this schema-aware wrapper, so only one connection pool is needed while each tenant's queries run against its own schema. Engineers implementing schema-per-tenant isolation in Spring Boot can dig into this pattern on daily.dev."}},{"@type":"Question","name":"Why should a JWT access token not be exposed directly in the browser for a web client that talks to a backend API?","acceptedAnswer":{"@type":"Answer","text":"Storing or handling the JWT in browser JavaScript is less secure and requires more code than relying on a server-side session tied to a cookie. Routing both the static frontend and backend API through a single gateway (e.g., Spring Cloud Gateway) lets the gateway hold the authenticated session in memory, attach the token to downstream requests itself, and avoid CORS issues since everything is served from the same domain. Anyone architecting secure session handling for a gateway-backed frontend can explore this reasoning on daily.dev."}}]}
```

