What are the available strategies for pagination or data filtering using microservice architecture?

Usually, when you have a monolithic application or data model, you can create an SQL connection to various tables and apply filters to them. Then, as soon as you receive the results, you can also send this data. But if you use a microservice architecture, the data model may be disparate. I heard that netflix actually takes this to the extreme where every table has a microservice. How can you handle paging and filtering in this case?

I know that they use the Gateway API template, which can act as an aggregation level (perhaps this is where RxJava projects appear). It would be great to have ideas from people using microservices, or to solve this problem.

+4
source share
1 answer

Pagination and filtering are performed even if there is only one table, right?

So, I think the question is how to join tables between microservices.

I think people use microservices to avoid as much table joining as possible between microservices. If they cannot, perhaps the tables should not be shared in different microservices at all.

, . , , :

-- from hotel information service
create table t_hotel (
    id VARCHAR(40) not null,
    name varchar(50) not null,
    location varchar(50) not null,
    CONSTRAINT pk_hotel PRIMARY KEY (id)
);

-- from hotel comment service
create table t_hotel_comment (
    id VARCHAR(40) not null,
    hotel_id varchar(40) not null,
    content varchar(50) not null,
    CONSTRAINT pk_hotel_comment PRIMARY KEY (id)
);

, , .

 ____________________________
| name | location | comments |
| foo  | foooooo  |        2 |
| bar  | barrrrr  |        3 |
 ----------------------------

, api:

  • , .
  • , .

, N + 1, t_hotel:

-- from hotel information service
create table t_hotel (
    id VARCHAR(40) not null,
    name varchar(50) not null,
    location varchar(50) not null,
    comments numeric not null,
    CONSTRAINT pk_hotel PRIMARY KEY (id)
);

, , HotelCommentedEvent

HotelCommentedEvent {
    "comment_id": "id",
    "hotel_id": "foo",
    "content": "bar"
}

. .

0

All Articles