Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8755439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:51:37+00:00 2026-06-13T13:51:37+00:00

My web application need to support scalability at both Web and DB tier. I

  • 0

My web application need to support scalability at both Web and DB tier.
I have the following components:

  1. N Web servers (Tomcat)
  2. M DB servers sharded by username as the shard key (PostgreSQL)

Our shard strategy as following:

  1. The shard strategy is lookup table based, we have one index table (username,shardId), the other shard table (shardId,connectionString,loading).

  2. We will monitor the shard DB periodically, and update the loading status field.

  3. When create new user, we always pickup the shard with lowest loading, and store to index table.

  4. The DB shards will be added or removed dynamically.

I have to implement an API like getDBConnection(username) to get one JDBC connection according to the shard key (in this case the login user).

The questions are :

1.How could I implement this API in a way that will work with a connection pool? Suppose each shard support 500 connections, how could i did this via Java code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:51:38+00:00Added an answer on June 13, 2026 at 1:51 pm

    I probably wouldn’t connection pool in the application at all, I’d probably just use server-side connection pooling with pgpool-II or pgbouncer.

    If I was to use in-application pooling I’d create per-shard connection pools and just pick a connection out of the appropriate pool for the shard. This will work with any connection pool implementation that lets you create pools programmatically, rather than declaratively. Each pool should try to close inactive connections quite aggressively. It looks like org.apache.tomcat.jdbc.pool.DataSource is suitable for this; see the Tomcat JDBC pool docs.

    Since this will result in potentially large numbers of connections sitting around and lots of connects/disconnects, it will be very important to also run a server side connection pool to limit and share connections to each shard. Use something like pgbouncer or pgpool-II in transaction pooling mode on each shard to share a relatively small number of real PostgreSQL connections out among the larger number of connections from web workers.

    I’d say you’ll want a pattern like this:

    web1 [pool1]-----------------------------[server1-pgbouncer]------[server1-pg]
         [pool2]-------------------------------v         ^
         [pool3]---------v        [server2-pgbouncer]-----------------[server2-pg]
                         |                     ^         |
                        [server3-pgbouncer]---------------------------[server3-pg]
                         |                     |         |
    web2 [pool3]---------^                     |         |
         [pool2]-------------------------------|         |
         [pool1]------------------------------------------
    

    where each app pool connects to a pgbouncer on the shard server corresponding to that pool, and only that shard server’s pgbouncer ever talks to the shard’s PostgreSQL instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have asp.net web application and we need to support automatic login using domain
I have a web application that will need to access code behind methods as
I have a web application which needs to support multiple languages. We currently have
I have a working web application that uses username/password SpringSecurity configuration. Now I want
I have a ASP.Net C# 4.0 Web Application I need to Add a scanning
I need to develop a web application, i have two choices mvc3 straight forward
I have implemented SignalR support for web application. It works great. The problem I'm
I am developing a web application that can support threaded comments. I need the
I currently have an ASP.NET web application written in C#, and I need to
In the java web application need to select the file from server and print

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.