Multi-tenancy: How to access multiple Keyspaces from a bean?

635 views
Skip to first unread message

ScheideckerAntunes

unread,
Jun 16, 2014, 6:32:23 AM6/16/14
to spring-dat...@googlegroups.com
Hello,

Another question, a little more involving.

Say I have user1 and user1 can access Keyspace1, user2 can do keyspace2 and so on.

How can I access different keyspaces depending on the user?

What I would like to do is a REST api that is multi-tenant.

In other words, user1 logs in and gets his credeantials checked against Cassandra's system_auth.

I then know that user1 can only access keyspace1.

How do I set up my REST api so that the repository for operations on Cassandra will only perform operations on that user's keyspace?

I wonder if I should have a Cassandra Bean for each user when he logs in and is active to its session.

Gets confusing when you have a connection pool. If each user can only access his own keyspaces.

In other words, how can I make this REST api multi-tenant ?

Thank you.

David Webb (Prowave)

unread,
Jun 16, 2014, 1:06:10 PM6/16/14
to ScheideckerAntunes, spring-dat...@googlegroups.com
You can create multiple CassandraSessionFactoryBeans for a given Cluster, passing in the different keyspace for each one you define in your Spring Config.

Determining which one you use for a given user will need to be handled by your application.


--
You received this message because you are subscribed to the Google Groups "Spring Data Cassandra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spring-data-cass...@googlegroups.com.
To post to this group, send email to spring-dat...@googlegroups.com.
Visit this group at http://groups.google.com/group/spring-data-cassandra.
To view this discussion on the web visit https://groups.google.com/d/msgid/spring-data-cassandra/90c201ff-e2de-4338-9c1a-83dcac446e5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ScheideckerAntunes

unread,
Jun 16, 2014, 2:18:33 PM6/16/14
to spring-dat...@googlegroups.com, cf.an...@gmail.com, dw...@prowaveconsulting.com
Thanks David. Can you just determine the Keyspace at run time?

Or can you just create a bean for the user after he authenticates and then destroy the bean when he logs off or his session expires?

Many users would be many beans and that should hurt performance.

David Webb (Prowave)

unread,
Jun 16, 2014, 2:29:59 PM6/16/14
to ScheideckerAntunes, spring-dat...@googlegroups.com
Sessions are tied to keyspaces, and are recommended to be final and static for performance reasons.  Keyspace per user is more of an anti-pattern with cassandra.  Why not just segment your data by user in the same keyspace?  

I don’t have any further advice since your design is independent of SDC*.
Reply all
Reply to author
Forward
0 new messages