Table of Contents
What is Nile
Developing a SaaS product can have a lot of complexity in lifecycle management and codifying best practices. These SaaS architectures have to address really hard problems, including:
- Multi-tenant control plane
- Event handling, e.g. reconciling the data plane with the control plane for infrastructure SaaS
- Metrics and consumption-based billing
- Control plane access control
- Consistent user experience for webapp UIs, REST APIs, SDKs (nile-js, nile-py)
- GUI for initial setup and management (Nile Admin Dashboard)
Nile provides a tenant-aware, serverless database that is used to build SaaS control planes and solves a lot of these problems out of the box. Think about all the problems above and how they all lie just under the surface of a SaaS webapp front-end. Check out https://demo-db-saas.thenile.dev (login as one of the predefined users), which is a mocked example of a SaaS that we built on top of Nile to demonstrate the ease with which you can deliver a SaaS infrastructure service (follow the webapp playbook for details).
This collection of examples demonstrates how to use Nile in a variety of ways. The examples can also be run sequentially to build on top of one another, in which case, we recommend running them in the order presented here to build up your SaaS as you go. Or jump to the webapp to run an end-to-end example for multi-tenancy, event handling, a metrics API, and a front-end for self-service provisioning.
Community
-
Join the Slack community for SaaS developers who are learning from and sharing with each other advice on how to build spectacular services in the cloud.
-
Subscribe to the SaaS Developer Community Youtube channel to hear experts in the field talk about how they solve SaaS problems.
-
Learn more about the SaaS space from the Nile blog.
-
If you have any questions, go to the Nile website and reach out to us!
Getting started
To get started:
- Setup your Nile workspace and environment
- Run the Quickstart to configure a minimal control plane in Nile.
You can then follow on with any of the other examples for different use cases.
Setup
Nile workspace and developer credentials
-
✅ Log into Nile Admin DashboardNavigate your web browser of choice to the Nile Admin Dashboard and click
Continue with Google
to login via SSO. (Don't want SSO? Go to the Nile website, enter your email address, and clickTalk to us
, then someone from Nile will contact you to setup up an email and password for you) -
✅ Create a Nile workspaceIf you don't already have a Nile workspace, create it now. From the dashboard, click
Create a workspace
, and in the textbox enter the name of a new workspace. This represents your control plane where your SaaS application lives. -
✅ Get your workspace access tokenFrom the dashboard, get your workspace access token. This token enables you to programmatically run the examples in this repo.
Your local environment
-
✅ Clone the GitHub repositoryFrom a terminal window, clone the theniledev/examples repo and change into the new directory.
git clone git@github.com:TheNileDev/examples.git cd examples
-
✅ Create a local.env
fileTo run any example, you need a local
.env
file with your Nile configuration. At the top-level of the examples, copy the .env.defaults file to a new file.env
, and then edit the values in the.env
file to match what you created in the dashboard. In particular, set the values of your Nile workspace and credentials to match what you have in the Nile Admin Dashboard.cp .env.defaults .env # edit file (set NILE_WORKSPACE, and {NILE_WORKSPACE_ACCESS_TOKEN} or {NILE_DEVELOPER_EMAIL and NILE_DEVELOPER_PASSWORD})
-
✅ Verify Node version (Javascript examples only)For the Javascript examples, validate your environment has the minimum required Node version v18.0.0 or higher. If you are running earlier versions, you may encounter errors such as
ReferenceError: fetch is not defined
. (If you usenvm
, runnvm use
).
Quickstart
Start with the quickstart to configure a base Nile control plane. This provides a simple setup to learn the concepts but also serves as the foundation for the other examples below.
- Quickstart with JS | JS SDK | Setup a minimal Nile control plane with a single tenant
- Quickstart with Python | Python SDK | Setup a minimal Nile control plane with a single tenant
Examples by Feature
Multi-tenancy
Tenants have access to specific organizations that have isolated sets of resources. Users are allowed to access only the entity instances in the organizations to which they have been added.
- Multi-tenancy with JS | JS SDK | Setup the Nile control plane with multiple tenants and users
- Multi-tenancy with Python | Python SDK | Setup the Nile control plane with multiple tenants and users
Data Plane
These examples show how to synchronize, e.g. reconcile, your data plane and control plane in real time with Nile events. As instances are created or destroyed from the control plane, the example reconciler creates or destroys data plane deployments. Even if you're using another deployment tool like Kubernetes or Terraform, similar principles apply as they do for Pulumi.
- Data Plane with Pulumi via JS | JS SDK | Synchronize your data plane and control plane
- Data Plane with Apache Flink and Kubernetes via JS | JS SDK | Synchronize a control plane built with Nile with data plane that uses Apache Flink and Kubernetes
- Data Plane with Apache Flink and Kubernetes via Python | Python SDK | Synchronize a control plane built with Nile with data plane that uses Apache Flink and Kubernetes
- Fake Data Plane via JS | JS SDK | Synchronize your fake data plane and control plane (if you don't have a real data plane to test)
Authorization
Attribute-based access control (ABAC) is an authorization model that gives you fine-grained authorization capabilities. You can configure these in the control plane so that they are aligned to your business's security policies.
- Authorization with JS | JS SDK | Use ABAC to grant and revoke permissions to resources
- Authorization with Python | Python SDK | Use ABAC to grant and revoke permissions to resources
- Authorization App Backend with JS | JS SDK | Authorize users against Nile control plane for your backend applications
Metrics
Nile provides a metrics API and matching UI components. This allows you to add real-time data features to your application, for example, each end user of your SaaS can see their real-time resource consumption and the cost incurred to date. Read more on the importance of metrics and consumption-based billing in the blog post Launching an Infrastructure SaaS Product, An Example Walkthrough.
- Metrics with JS | JS SDK | Produce and get mock metrics
Webapp
Launch a front-end web application that is customizable on a per-tenant basis. The webapp includes Nile React components for login, Google SSO, managing entities, filtering metrics, and more.
- Webapp | JS SDK | Builds a self-service frontend that integrates with Nile on the backend
Other
Here are additional examples that are more developed end-to-end applications.
- Python + Flask Todo List Webapp | Python REST | Take a basic Todo List webapp written in Python and Flask and turn it to a PLG SaaS product with Nile APIs
- ETL | Python SDK | Create a self-service ETL pipeline, connecting one source system (Confluent Cloud) to another end system (Snowflake)
Examples by Language
Note: the languages and examples shown are an indication just of which examples have been developed, not of what's available. Please see the Nile API and SDK documentation for details.
Javascript
These examples use the nile-js SDK.
- Quickstart with JS | JS SDK | Setup a minimal Nile control plane with a single tenant
- Multi-tenancy | JS SDK | Setup the Nile control plane with entities and multiple tenants and users
- Data Plane with Pulumi via JS | JS SDK | Synchronize your data plane and control plane
- Data Plane with Apache Flink and Kubernetes via JS | JS SDK | Synchronize a control plane built with Nile with data plane that uses Apache Flink and Kubernetes
- Fake Data Plane via JS | JS SDK | Synchronize your fake data plane and control plane (if you don't have a real data plane to test)
- Authorization with JS | JS SDK | Use ABAC to grant and revoke permissions to resources
- Authorization App Backend with JS | JS SDK | Authorize users against Nile control plane for your backend applications
- Webapp | JS SDK | Builds a self-service frontend that integrates with Nile on the backend
Python
These examples use the nile-py SDK.
- Quickstart with Python | Python SDK | Setup a minimal Nile control plane with a single tenant
- Multi-tenancy with Python | Python SDK | Setup the Nile control plane with entities and multiple tenants and users
- Data Plane with Apache Flink and Kubernetes via Python | Python SDK | Synchronize a control plane built with Nile with data plane that uses Apache Flink and Kubernetes
- Authorization with Python | Python SDK | Use ABAC to grant and revoke permissions to resources
- Python + Flask Todo List Webapp | Python REST | Take a basic Todo List webapp written in Python and Flask and turn it to a PLG SaaS product with Nile APIs
- ETL | Python SDK | Create an ETL pipeline from one source system to another end system
Advanced
Change Entity Type
The default scenario in these examples is a company that provides a database as SaaS, as is defined in your .env
file where NILE_ENTITY_NAME=DB
(see Setup).
However, you can modify the NILE_ENTITY_NAME
parameter to be another entity type to fit another usecase.
See here for more details.
Run in Gitpod (Experimental)
Try out the examples in Gitpod.
Known limitation: webapp won't work
Testing
The examples are validated via GitHub Actions, a flexible CI/CD tool that executes the examples against Nile. For more details, view this repo's workflow.