Build a High‑Performance AI Chatbot with FUST Microservices and DeepSeek

This tutorial walks through using Zhihu's open‑source FUST microservice framework together with DeepSeek's language model API to design, implement, and deploy a scalable, high‑performance intelligent Q&A system, covering architecture, data models, service layers, and deployment scripts.

Zhihu Tech Column
Zhihu Tech Column
Zhihu Tech Column
Build a High‑Performance AI Chatbot with FUST Microservices and DeepSeek

In recent years, with the rapid development of large language models, intelligent Q&A systems have become essential tools for enterprises to improve user experience and reduce customer service costs. This article introduces how to use Zhihu's open‑source FUST microservice framework and DeepSeek API to build a high‑performance, scalable intelligent Q&A system.

FUST (pronounced Fast) is a Spring Boot‑based microservice framework developed by Zhihu, designed to help developers quickly construct high‑quality microservice applications. It integrates mainstream components, provides standardized development patterns, and has been proven in Zhihu’s large‑scale production environment.

We will implement a project named “Deep QA” to demonstrate combining FUST with DeepSeek API to create a fully functional intelligent Q&A system.

2. Technology Stack Overview

2.1 FUST Framework

FUST is built on Spring Boot 3.x and offers the following advantages:

Out‑of‑the‑box : integrates mainstream components and provides standardized development patterns

High performance : built on high‑performance Spring Boot 3.x and Armeria

Observability : includes complete monitoring and tracing solutions

Flexible extensibility : rich extension points for various custom needs

Production‑validated : proven in Zhihu’s large‑scale production environment

2.2 DeepSeek API

DeepSeek provides a series of powerful language model APIs, including:

deepseek-chat : general conversation model

deepseek-coder : code generation and understanding model

3. Project Architecture

Deep QA adopts a classic multi‑module microservice architecture, mainly containing two core modules: deep-qa/ This modular design offers the following benefits:

Separation of concerns : API layer handles HTTP requests/responses, business layer handles core logic

Code reuse : business logic can be reused by different interface layers (HTTP, gRPC)

Testability : each layer can be tested independently

Maintainability : clear module boundaries reduce coupling

4. Environment Preparation

Before starting development, prepare the following environment:

JDK 17+

Maven 3.8+

MySQL 5.7+

Redis 6.0+

DeepSeek API key

# Clone FUST repository
git clone https://github.com/zhihu/fust.git
cd fust
# Publish to local Maven repository
./gradlew publishToMavenLocal

5. Project Implementation

5.1 Project Configuration

The parent project's pom.xml configuration:

<parent>
  <groupId>com.zhihu.fust</groupId>
  <artifactId>fust-boot-bom</artifactId>
  <version>0.1.0</version>
</parent>

We use the FUST fust-boot-bom as the parent to manage dependency versions uniformly.

5.2 Data Model Design

In the deep-qa-business module, the main data models are defined, e.g., the chat history model:

@Data
@Table(name = ChatHistoryModel.TABLE_NAME)
public class ChatHistoryModel {
    public static final String TABLE_NAME = "t_chat_history";
    /** Primary key ID */
    @Id
    private Long id;
    /** Creation time */
    @DbAutoColumn
    private LocalDateTime createdAt;
    /** Update time */
    @DbAutoColumn
    private LocalDateTime updatedAt;
    /** User ID */
    private Long userId;
    /** Session ID */
    private String sessionId;
    /** Role (user/assistant) */
    private String role;
    /** Message content */
    private String content;
    /** Whether contains image */
    private Boolean hasImage;
    /** Image URL */
    private String imageUrl;
}

The @DbAutoColumn annotation marks fields for automatic filling; FUST handles creation and update automatically.

5.3 Data Access Layer

The data access layer uses MyBatis; FUST provides the TemplateDao interface to simplify common CRUD operations. Example ChatHistoryDao:

@Mapper
public interface ChatHistoryDao extends TemplateDao<ChatHistoryModel> {
    /** Query chat records by user ID and session ID */
    @Select({"SELECT * FROM ", ChatHistoryModel.TABLE_NAME,
             " WHERE user_id = #{userId} AND session_id = #{sessionId} ORDER BY created_at ASC"})
    @ResultMap("ChatHistoryModel")
    List<ChatHistoryModel> findByUserIdAndSessionId(@Param("userId") Long userId,
                                                    @Param("sessionId") String sessionId);

    /** Delete session records */
    @Delete({"DELETE FROM ", ChatHistoryModel.TABLE_NAME,
             " WHERE user_id = #{userId} AND session_id = #{sessionId}"})
    int deleteByUserIdAndSessionId(@Param("userId") Long userId,
                                   @Param("sessionId") String sessionId);

    /** Get recent sessions for a user */
    @Select({"SELECT DISTINCT session_id FROM ", ChatHistoryModel.TABLE_NAME,
             " WHERE user_id = #{userId} ORDER BY MAX(created_at) DESC LIMIT #{limit}"})
    List<String> findRecentSessionsByUserId(@Param("userId") Long userId,
                                            @Param("limit") int limit);
}

5.4 Business Service Layer

The service layer implements core business logic. Example ChatService interface:

public interface ChatService {
    /** Send a message */
    ChatHistoryModel sendMessage(Long userId, String sessionId, String message);
    /** Get chat history */
    List<ChatHistoryModel> getChatHistory(Long userId, String sessionId);
    /** Get user session list */
    List<String> getUserSessions(Long userId, int limit);
    /** Create a new session */
    String createNewSession(Long userId);
    /** Delete a session */
    boolean deleteSession(Long userId, String sessionId);
}

Implementation ChatServiceImpl handles saving user messages, retrieving context, calling DeepSeek API, and persisting AI replies, with proper exception handling.

5.5 DeepSeek API Integration

The DeepSeekClient class interacts with the DeepSeek API, providing methods to generate responses, list available models, and test connectivity:

@Component
public class DeepSeekClient {
    private static final Logger LOGGER = LoggerFactory.getLogger(DeepSeekClient.class);
    /** Generate a response from DeepSeek */
    public String generateResponse(ConfigModel config, String prompt,
                                   List<Map<String, String>> history) { /* ... */ }
    /** Get available models */
    public List<String> getAvailableModels(String serverUrl, String apiKey) { /* ... */ }
    /** Test connection */
    public boolean testConnection(String serverUrl, String apiKey) { /* ... */ }
}

5.6 Web Controller Layer

The controller layer handles HTTP requests. Example ChatController provides endpoints for sending messages and retrieving chat history:

@RestController
@RequestMapping("/api/chat")
public class ChatController {
    private static final int MAX_SESSIONS_COUNT = 10;
    private static final int SESSION_TITLE_LENGTH = 8;
    private final ChatService chatService;
    @Autowired
    public ChatController(ChatService chatService) { this.chatService = chatService; }

    /** Send message */
    @PostMapping("/send")
    public ResponseDTO<ChatMessageDTO> sendMessage(@RequestBody SendMessageRequestDTO request) { /* ... */ }

    /** Get chat history */
    @GetMapping("/history/{sessionId}")
    public ResponseDTO<List<ChatMessageDTO>> getChatHistory(@PathVariable String sessionId) { /* ... */ }

    private ChatMessageDTO convertToDTO(ChatHistoryModel model) { /* ... */ }
}

FUST’s unified ResponseDTO ensures consistent API responses.

5.7 Application Startup

The main class starts the Spring Boot application and initializes telemetry:

@SpringBootApplication
@Import(ServiceConfiguration.class)
@ComponentScan(basePackages = {"com.deepqa.api", "com.deepqa.business"})
@EntityScan(basePackages = {"com.deepqa.business.model"})
public class DeepQAMain {
    public static void main(String[] args) {
        if (System.getProperty("env.name") == null && System.getenv("ENV_NAME") == null) {
            System.setProperty("env.name", "dev");
        }
        TelemetryInitializer.init();
        SpringApplication app = new SpringApplication(DeepQAMain.class);
        app.setAdditionalProfiles("api");
        app.run(args);
    }
}

6. Project Build and Run

6.1 Build

Compile the Maven project: mvn clean package Then run the build script:

bash build.sh

6.2 Run

Use environment‑specific scripts.

Development environment

# Use development environment
source ./dev-env.sh
# Run HTTP service
bash run.sh deep-qa-api/target

Production environment

# Set production DB credentials (do not hard‑code sensitive info)
export DB_USER="production_username"
export DB_PASSWORD="production_password"
# Use production environment
source ./prod-env.sh
bash run.sh deep-qa-api/target

Service is accessible at http://localhost:8080/.

8. Conclusion and Outlook

The article demonstrated how to build a complete intelligent Q&A system using FUST and DeepSeek API, highlighting modular architecture, extensibility, high performance, reliability, and built‑in observability.

JavaSpring BootDeepSeekAI chatbotFUST
Zhihu Tech Column
Written by

Zhihu Tech Column

Sharing Zhihu tech posts and exploring community technology innovations.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.