In a SaaS solution, that allows users to maintain their data on the server, if I have to implement various pricing schemes, where each scheme offers different storage quota, say, Basic subscription gets you 2GB storage, whereas Premium gets you 10GB storage - what kind of architecture one has to use?Do I need to maintain against user profile the quota being used?Will this work only if data is maintained in file system?  What happens if data is stored in relational or NoSQL database - how one keeps track of user-level usage of storage in such cases?
Implementing per-user storage usage quota in SaaS products
architecture;software as a service
Add a size field to each thing that is stored.  This field could be approximate, but it should be updated to reflect the new size whenever the item is modified.Add a space_used field on the User. Whenever something with a size is added or modified, run a query for all the items the user owns, sum the size fields, and update the space_used field on the user.  If you aren't using a relational database, you could try little efficiency tricks like just adding or subtracting the size change of the item they just modified, but this will fail if there is any possible way that a user could modify 2 items at once.Either on the User, or on the Company (depending on who is paying for the licenses) you need to store the space_quota to compare against.The result:You'll have to check User.space_used < space_quota before allowing the user to add any items or increase the size of any items, so space_used needs to be pre-calculated to keep the query fast.  You need Item.size to later answer the question, How did we calculate User.space_used because it looks wrong?Using such a system, it should be easy to give the user warning when they reach 80% or 95% of their quota.