Multiple Instances of V5 connected to one Database


I wanted to find out if it was possible to have 2 separate V5 installs connected to the same database?

At the moment we’re running V5 off shared hosting which is working fine however it is a bit slow.
I want to do some testing to see if installing Invoice Ninja on a VPS I have will have any impact on our speeds

What I was thinking was installing V5 using docker on a VPS that I have and using the db details from our shared hosting provider because as far as I can see, all data is stored in the db and the actual application folder is only used to store the logo as well as documents attached to invoices.

Would this actually work? Would I be able to run 2 instances at the same time?


What part of the app is slow? I would think enabling queues and using the desktop app would have a larger performance impact than changing servers.

@david what do you think?

Queues should be enabled
I did change it to ‘QUEUE_CONNECTION=database’ with the required cron job
I am using the desktop app

I see the slowness when first starting up Invoice Ninja, on the side bar you can see the loading icon going through each item

Next is saving quotes/invoices, it takes way longer than what I would expect. This could also be down to our provider which is something I want to test as well

And last one is PDF generation, this is more than likely due to Phantom Cloud so I want to test snappdf on an Ubuntu server to see if theres any improvement to be had there

In general a VPS is going to be much more powerful than our shared hosting and we don’t need to worry about space so much as we are nearing our limits on our plan

Thanks for the details!

For the slowness when starting the app enabling persist data on Settings > Device Settings will have the app retain the data so it will start much quicker once you’ve logged in. Another option is to change to the React app which doesn’t load all of the data when logging in.

The speed it takes to save is one area where different hosting can make a difference.

Very likely, running SnapPDf locally is much faster.

I will definitely be switching to the React app once its more feature complete, I remember seeing someone recently that there’s now a button to switch to React but in React there’s no button to switch back so I will be waiting on that

So is it possible to have 2 instances connected to the same database?
I could also just clone the database and test on that but it would help if 2 instances can be connected to the same db

I don’t think it should be a problem, it’s how we run our hosted server to support load balancing.

I want to note that we recently deployed Dockerized InvoiceNinja (latest v4.5.50) on AWS Fargate, MySQL on RDS. When we tried to run multiple containers (running instances of the same InvoiceNinja) we would get logged out of invoiceNinja when the load balancer switched us between the two running containers. So in theory this could work, but would probably need to ensure that a load balancer does not switch instances…or somehow modify the Laravel session/csrf token generation to ensure it doesn’t change between requests.

You would need some kind of session persistence between the containers using a shared redis or similar.

Is there any documentation specific to InvoiceNinja on how to best configure this (running multiple app instances of IN)? Or should I look for examples on how this is done with Laravel.

I don’t think this is specific to invoice ninja or laravel. The issue here is session persistence, if you want to use a distributed system, you’ll need to ensure each instance has access to the store which manages the session.

I believe it is possible to setup load balancers to have sticky persistence which could be an alternative.

I’m about set up a cluster of redundant, load-balanced invoiceninja (docker-compose’d) instances as well. I’m assuming that using SESSION_DRIVER: database should take care of the problem discussed here.

Additionally, I will assume I can safely mount the storage directories on an NFS volume shared by the instances.

Would there be any other state that I would need to explicitly externalize?

cache_driver will need to be distributed also ie: redis

Right. Though am I correct in assuming having local caches would not affect the application’s integrity, just performance (due to redundant caching)?

When you say load balanced, i assume that any container can answer a request… if this is true, then the cache will also need to be distributed.

Yes, consecutive requests could be routed to any backend instance. I’ll set up a Redis instance then.

While I have you; the storage path for uploaded files can safely be put on an NFS mount shared among all nodes?

as long as any instance can read/write to the storage path it will be happy.