English 中文(简体)
戈兰高地 B. 要求下游服务提供数据的战略
原标题:Golang Fallback Caching Strategy when requesting data from downstream services
  • 时间:2023-12-11 08:38:50
  •  标签:
  • go
  • redis

该职能向下游部门发出一项要求,以检索一些数据;主要服务严重依赖Redis。 我想实施一项战略,以减少对主要服务的影响,如果下游服务再出现故障。 目前,我的想法是,如果下游服务或再服务有:

var SendDownstreamServiceTypeRequest = func(ctx context.Context, param1 int64) ([]ds.ServiceType, error) {
    var rsp *Response
    cachedResult, err := getCachedInfo(ctx, param1)
    if err == nil {
        logger.SetLoggerContext(ctx, "UsingCache", true)
        rsp = &Response{Data: cachedResult}
    } else {


        fallbackCachedResult, fallbackErr := getFallbackCachedInfo(ctx, param1)
        if fallbackErr == nil {
            logger.SetLoggerContext(ctx, "UsingFallbackCache", true)
            rsp = &Response{Data: fallbackCachedResult}
        } else {
            // ... request from downstream service
            // ... 
            // add response data from downstream service to primary cache and fallback cache
            errPrimaryCache := setCachedInfo(ctx, param1, rsp.Data)
            if errPrimaryCache != nil {
                logger.SetLoggerContext(ctx, "UsingCache", err.Error())
            }
            errFallbackCache := setFallbackCachedInfo(ctx, param1, rsp.Data)
            if errFallbackCache != nil {
                logger.SetLoggerContext(ctx, "UsingFallbackCache", err.Error())
            }
        }


    }
    var result ds.Response
    err = json.Unmarshal(rsp.Data, &result.Data)
    if err != nil {
        return nil, err
    }
    return result.Data, nil
}

Is there any better fallback caching strategy that can be implemented into the main service in order to add more redundancies? Thanks

问题回答

退席的红色审判会奏效,但我认为,由于你必须维持另一个红星场,以及支付其主办费用,因此成本会更高。

除此以外,还有一种选择,就是在服务本身上安装一个内层笼子;将数据储存在主要服务的记忆中。 部分 能够轻松落实的图书馆是:。 因此,数据流将首先从案例的记忆中检索——和;cache->数据库。

在服务中使用一流式切记的同时,如果你有多种相同服务,因为你必须适当总结彼此之间的数据。 因此,你可能必须执行一个条令,每X年清理中流切,或清理发生事件时所储存的数据。 可以通过使用像样的电传(例如:NSQ、RabbitMQ、Kafka等)来做到这一点。

希望:





相关问题
How do you mix SQL DB vs. Key-Value store (i.e. Redis)

I m reviewing my code and realize I spend a tremendous amount of time taking rows from a database, formatting as XML, AJAX GET to browser, and then converting back into a hashed javascript object ...

Predis sharding (consistent hashing)

Predis claim to have Client-side sharding (support for consistent hashing of keys). http://github.com/nrk/predis I can do sharding using connect to an array of profiles (nodes) but it isn t ...

key value stores for extendable objects

http://www.infoq.com/presentations/newport-evolving-key-value-programming-model is a video about KV stores, and the whole premise is that redis promotes a column-based style for storing the attributes ...

nginx/redis and handling tracking params in url

I am using nginx and redis in my website. For several items on my site, I want to add tracking params to their urls so that when a user clicks on an item, I can collect statistics of user usage apart ...

热门标签