Which DB? Both SQL Server and Oracle, for example, can support counting for you in an indexed (materialized) view. For example, on SQL Server:
create view Metric with schema binding as select count_big(*) as RegisteredUserCount from dbo.users where ...; create clustered index cdxMetric on Metric(RegisteredUserCount);
The engine will keep this counter accurate for you, see Improving Performance with SQL Server 2008 Indexed Views :
select RegisteredUserCount from dbo.Metric with (NOEXPAND);
Alternatively, you can cache this result and get automatic revocation, see LinqToCache .
If you are using a system with MySQL support, then probably the best way is to count it once, save the account in memcached and update it when registering a new user.
source share