DataStax Academy FAQ

DataStax Academy migrated to a new learning management system (LMS) in July 2020. We are also moving to a new Cassandra Certification process so there are changes to exam bookings, voucher system and issuing of certificates.

Check out the Academy FAQ pages for answers to your questions:


question

andrei_192823 avatar image
andrei_192823 asked ·

How bad is it to have a lot of connections per AWS Keyspace using serverless AWS lambdas with the node.js driver?

[FOLLOW UP QUESTION TO #5885]

We've read a best practices of using node driver here https://docs.datastax.com/en/developer/nodejs-driver/4.5/coding-rules/

It says "Only use one Client instance per keyspace or use a single Client and explicitly specify the keyspace in your queries and reuse it in across your modules in the application lifetime."

In theory, how bad is that we basically have a lot of connections per AWS Keyspace because we are using serverless(AWS lambdas)? Because for example if we have some "Posts" entity and it has near 20 endpoints for different manipulations(CRUD + some extra methods). In AWS Lambda it means that we have at least 20 connections per Keyspace, not saying about that Lambda is some sort of container with cold/warm start.

Thanks!

aws keyspacesnode.js driveraws lambdas
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

Speaking generally, it is fine to have multiple application instances connecting to a Cassandra cluster. In your case, those app instances just happen to be AWS lambdas.

The best practices document is referring to a distinct app instance only using one Cassandra Client() instance that is shared throughout the code of that same same instance.

This is a good use of the same Client() instance:

App instance 1 App instance 2
  ...
  const client = new c.Client( ... );
  ...
  client.execute(queryA);
  ...
  client.execute(queryB);
  ...
  client.execute(queryC);
  ...
  ...
  const client = new c.Client( ... );
  ...
  client.execute(queryX);
  ...
  client.execute(queryY);
  ...
  client.execute(queryZ);
  ...

This is a bad example where app instances are creating multiple Client() instances:

App instance 11 App instance 12
  ...
  const client1 = new c.Client( ... );
  client1.execute(queryD);
  ...
  const client2 = new c.Client( ... );
  client2.execute(queryD);
  ...
  const client3 = new c.Client( ... );
  client3.execute(queryE);
  ...
  ...
  const client4 = new c.Client( ... );
  client4.execute(queryU);
  ...
  const client5 = new c.Client( ... );
  client5.execute(queryV);
  ...
  const client6 = new c.Client( ... );
  client6.execute(queryW);
  ...

I hope I got that right. I'm going to reach out to the DataStax Drivers team for their perspective and maybe someone like @jorgebg or @joao.reis can share their thoughts (or correct me :) ). Cheers!

1 comment Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

P.S. It's always a challenge responding to questions about AWS Keyspaces because there's limited public information about what's under the hood. My hypothesis is that it isn't a true Cassandra DB -- that it's backed by a Dynamo DB and an API engine sits on top that accepts CQL. But who knows, really? :shrug:

0 Likes 0 · ·