8. Multiple instances
1. Rent an another server / create new heroku
application / whatever,
2. Buy a domain,
3. Configure everything,
4. Deploy a copy of the blog engine there.
9. Multiple instances
● Very easy at the beginning,
● fixed price per instance* (server / hardware /
database / licences / external services ),
● $100 to host a blog with 50 000 UU for you,
● $100 to host a blog with 5 UU for your friend,
● $100 dollars for every new instance,
● deploy, administrate, backup separately,
● separate admin panels etc., no easy way to
i.e. collect data from several applications
* Instance = application process(es) + database + (...)
12. Multitenancy
● One application instance serves all the
blogs,
● One database for all the blogs,
● No need to pay for the external services
separately?,
● Easier to scale:
○ count traffic for all the blogs,
○ just add more heroku dynos or application processes
when needed
14. Multitenancy
1. Add root element to data structures:
● User has a blog_id
● Post has a blog_id
● etc.
2. At storage and configuration level
● keep the data for every tenant in a separate
storage
● dynamically switch the storage before
accessing the data
16. PostgreSQL schemas
● a namespace
● a group of tables
● an extra layer between a database and a
table
● just an extra dot :)
○ <table_name>.<column_name>
○ <schema_name>.<table_name>.<column_name>
17. PostgreSQL schemas
● every tenant uses its own schema,
● tables with common data are not in schemas
( in fact they are in ‘public’ schema )
30. PostgreSQL schemas
blogs=# SET search_path TO rails_tips, public;
SET
blogs=# SELECT * FROM posts;
title
| content
----------------------+----------Active Record basics | blah blah
(1 row)
33. Practice
● usually used with subdomains,
● a client organization / a workspace / any
isolated unit = tenant ?
● simpler application design and architecture,
● less chance for the data leak
36. Rails
Active Record + pg gem:
● supports schemas (create, drop, list),
● can manipulate search path,
● people prefer to execute SQL statements
anyway,
● supports the same operations on the tables
within schema as on the public ones
43. Useful information
●
●
●
●
●
influitive / apartment (gem)
pow server
classes and methods to work in console
don’t forget about security
subdomains and schemas in testing
environment (lots of helpers needed),
● rescue, sidekiq