Same android app connecting to multiple database -concept

I am looking for best method to create application which are connected to different databases based on client

So basically it is a multi tenancy model for an android app (enterprise use)

Deploy the same app to different customers but connect to different database for different customer.

The things I thought about is making a key and for each customer the key varies and a correct webservice will be contacted based on the key ( individual webservices for each client)?

Has anyone done something similar? What is the best method to approach this.
Thanks

In any case you will require a server API (webservice, REST or similar) to connect your Android app to the database. Assuming your database is available through such an API, there are two options.

  1. Design the database & server to serve multiple customers (multi-tenancy). With this your server API will expect the tenancy selection to happen on a per-request basis (e.g. a HTTP header or a query attribute), or at session initialization (e.g. when the user logs in).

    REST example:

    # get customers for tenant ABC
    GET example.com/api/customer/?tenant=ABC
    # create a new customer for tenant ABC
    POST example.com/api/customer/?tenant=ABC
    

    Obviously, your server will have to make sure clients can only access data that they are allowed to. Instead of passing the tenant as a query parameter, it can also be passed as an HTTP header or set as part of the session.

  2. Create different API endpoints, with each endpoint connecting to a different database. In this case your Android app needs to be configurable in some manner, e.g. by requesting the API endpoint to use from (say) the central login server.

    Example:

    # Request API endpoint to use
    # we assume the configuration response to contain the apiUrl parameter
    apiUrl = GET login.example.com/configuration/?user=XY
    GET <apiUrl>/customer/
    ...
    

    The server will run multiple endpoints, e.g. abc.example.com or xyz.example.com for tenants ABC and XYZ, respectively. So the actual API calls will look like this:

    # get customers for tenant ABC 
    GET abc.example.com/customer
    # get customers for tenant XYZ
    GET xyz.example.com/customer
    

As always with engineering decisions, there are a couple of trade-offs to consider:

  1. Data secrecy/segregation v.s. operation efficiency. Multitenancy is relatively simple to solve in a database (add a tenantfield or similar to at least the core tables of your data model, or every table for that matter). Operating one database is easier than operating many. However, in some industries you may need to keep data in separate databases.

  2. Declarative v.s. explicit client code. In the first example, your app client needs to be aware of the actual tenant it runs for to be able to send the right parameters to the server. In the second example, all that the app client needs to know is the endpoint’s URL to connect to.

Note that the first and second example could also be mixed:

  • In the second example, the same database can be used for different customers. To do so, run a front-end webserver that adds a tenant header to the HTTP request depending on the API endpoint.

  • In the first example, the server could route the request to a different database depending on the tenant selection. Some frameworks make such routing trivial, e.g. Django has a database router built-in.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật