Prerequisites
Before starting, ensure you have:- Two Upsun projects (we’ll call them
primary-dbandreplica-db) - Basic understanding of Upsun project configuration
- Access to the Upsun CLI (
upsuncommand) - Familiarity with MariaDB or MySQL databases
Understanding Upsun project isolation
Upsun’s architecture intentionally isolates projects from each other.- Isolated projects: Projects containers cannot directly communicate with another container in another project
- Secure ingress: Only designated routes are publicly accessible
- Internal service discovery: Applications can only be linked to services within their own project
Use cases for cross-project connectivity
Database replication scenarios
- Cross-region backup: Replicate data to different geographical regions
- Disaster recovery: Maintain standby databases in separate projects
- Data warehousing: Extract data from production to analytics projects
Service integration patterns
- Legacy system integration: Connect modern applications with legacy services
- Microservices architecture: Bridge services temporarily or permanently
- Multi-tenant isolation: Connect tenant-specific services across projects
What is Chisel?
Chisel is an open-source tunneling solution that creates secure, encrypted connections over HTTP/HTTPS. Key features include:- SSH-encrypted tunnels: All traffic is encrypted using SSH protocol
- HTTP transport: Tunnels work through firewalls and proxy servers
- Reverse port forwarding: Services can expose ports securely across networks
- Single binary: Easy to deploy with no external dependencies
- Auto-reconnection: Maintains stable connections with exponential backoff
How Chisel works
Chisel operates with a client-server model:- Chisel Server: Runs on the target project and listens for connections
- Chisel Client: Connects to the server and creates local tunnel endpoints
- Encrypted Tunnel: All traffic flows through SSH-encrypted HTTP connections
Setting up the MariaDB replication example
Now let’s implement a practical example: setting up MariaDB replication between two Upsun projects using Chisel tunnels.Architecture overview
Our setup includes:- Primary Project (
primary-db): Hosts the primary MariaDB instance - Replica Project (
replica-db): Hosts the replica MariaDB instance - Chisel Server: Runs alongside the primary database
- Chisel Client: Runs alongside the replica database
- Encrypted Tunnel: Connects replica to primary for replication traffic
Step 1: Configure the primary database project
First, let’s set up the primary database with MariaDB and Chisel server. Create.upsun/config.yaml in your primary project:
Configuration breakdown
Services section:maindb: MariaDB 11.4 service with two endpoints:mysql: Standard admin endpoint for general database operationsreplicator: Dedicated endpoint withreplicationprivileges for replica connections
rotate_passwords: false: Keeps passwords stable for replication connections
type: golang:1.24: Uses Go runtime (Chisel is a golang application)relationships: Creates two database connections:db: Admin access to the databasereplication: Replication-only access for the replica to connect to
hooks.build: Installs Chisel during the build phaseweb.commands.start: Runs Chisel server as the web processlocations: Configures HTTP handling with passthrough and disabled request buffering
- Exposes the Chisel server publicly via HTTPS
- Disables caching for real-time tunnel connections to be made over WebSockets
Deploy the primary project
Once added to your project, push the updated configuration to deploy the project:- The URL of this environment, here
https://main-bvxea6i-qwoo2yqnr6vgq.eu-3.platformsh.site/ - The password needed for the
replication.internalrelationship
Step 2: Configure the replica database project
Thereplicator endpoint in the primary configuration automatically creates the replication user with proper privileges, no manual SQL setup required!
Create .upsun/config.yaml in your replica project:
While we are hardcoding the endpoint in this example, you could also use the Upsun CLI in the environment to dynamically retrieve the correct route of the other project.
replicadb: Local MariaDB instance that will serve as the replica- Single
replica-adminendpoint withreplication-adminprivileges for managing the replica - A relationship from that MariaDB instance to the application
app: Chisel client application that creates the tunnelhooks.build: Installs Chisel during buildweb.commands.start: Runs Chisel client with specific tunnel configuration:- Connects to the primary server at
https://main-bvxea6i-qwoo2yqnr6vgq.eu-3.platformsh.site/. This is the URI generated at the previous step. - Creates tunnel:
0.0.0.0:3306:replication.internal:3306 - This forwards local port 3306 to the primary’s replication endpoint
- Connects to the primary server at
admin: Application managing the local MariaDB instance (circular relationships are not allowed, so a separate application is needed)
⚠︎ Because both projects are independent, the endpoint route might change based on the other project configuration.
0.0.0.0:3306: Binds to all interfaces on port 3306 (MySQL default)replication.internal:3306: Connects to the primary’s replication endpoint- The
replication.internalhostname corresponds to thereplicationrelationship defined in the primary project
app application via the relationship, it will be tunneled to the remote MariaDB instance.
Routes section:
- Routes traffic to the admin application for managing/querying the replica
Deploy the replica project
Once added to your project, push the updated configuration to deploy the project:Step 3: Verify replication is working
Connect to your replica database and check replication status:Key advantages of this setup
- Secure tunnel: All replication traffic flows through encrypted Chisel tunnel
- Minimal configuration: No custom scripts needed. Chisel handles everything
- Runtime agnostic: Works with any Upsun runtime (Go, Python, Node.js, PHP, etc.)
- Production ready: Built-in auto-reconnection and error handling
- Cost effective: Because the Chisel application is mostly a proxy, it can work with 0.1 CPU
Alternative approaches
While Chisel provides excellent flexibility, consider these alternatives:Upsun-native patterns
- Data export/import: Use regular data dumps and imports for less critical scenarios
- Message queues: Use RabbitMQ or Redis for event-driven data synchronization
- API-based sync: Build REST/GraphQL APIs for controlled data access
- Shared storage: Use external object storage for file-based data sharing
When to avoid cross-project connectivity
- Simple data sharing: Use APIs instead of direct database access
- Occasional data sync: Manual export/import may be simpler
- High-security environments: Additional network paths increase attack surface
- Performance-critical paths: Direct database connections may introduce latency